Python wx.BitmapFromBufferRGBA() Examples

The following are 15 code examples of wx.BitmapFromBufferRGBA(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module wx , or try the search function .
Example #1
Source File: backend_wx.py    From Computable with MIT License 6 votes vote down vote up
def draw_image(self, gc, x, y, im):
        bbox = gc.get_clip_rectangle()
        if bbox != None:
            l,b,w,h = bbox.bounds
        else:
            l=0
            b=0,
            w=self.width
            h=self.height
        rows, cols, image_str = im.as_rgba_str()
        image_array = np.fromstring(image_str, np.uint8)
        image_array.shape = rows, cols, 4
        bitmap = wx.BitmapFromBufferRGBA(cols,rows,image_array)
        gc = self.get_gc()
        gc.select()
        gc.gfx_ctx.DrawBitmap(bitmap,int(l),int(self.height-b),int(w),int(-h))
        gc.unselect() 
Example #2
Source File: backend_wx.py    From matplotlib-4-abaqus with MIT License 6 votes vote down vote up
def draw_image(self, gc, x, y, im):
        bbox = gc.get_clip_rectangle()
        if bbox != None:
            l,b,w,h = bbox.bounds
        else:
            l=0
            b=0,
            w=self.width
            h=self.height
        rows, cols, image_str = im.as_rgba_str()
        image_array = np.fromstring(image_str, np.uint8)
        image_array.shape = rows, cols, 4
        bitmap = wx.BitmapFromBufferRGBA(cols,rows,image_array)
        gc = self.get_gc()
        gc.select()
        gc.gfx_ctx.DrawBitmap(bitmap,int(l),int(self.height-b),int(w),int(-h))
        gc.unselect() 
Example #3
Source File: backend_wx.py    From neural-network-animation with MIT License 6 votes vote down vote up
def draw_image(self, gc, x, y, im):
        bbox = gc.get_clip_rectangle()
        if bbox != None:
            l,b,w,h = bbox.bounds
        else:
            l=0
            b=0,
            w=self.width
            h=self.height
        rows, cols, image_str = im.as_rgba_str()
        image_array = np.fromstring(image_str, np.uint8)
        image_array.shape = rows, cols, 4
        bitmap = wx.BitmapFromBufferRGBA(cols,rows,image_array)
        gc = self.get_gc()
        gc.select()
        gc.gfx_ctx.DrawBitmap(bitmap,int(l),int(self.height-b),int(w),int(-h))
        gc.unselect() 
Example #4
Source File: backend_wx.py    From ImageFusion with MIT License 6 votes vote down vote up
def draw_image(self, gc, x, y, im):
        bbox = gc.get_clip_rectangle()
        if bbox != None:
            l,b,w,h = bbox.bounds
        else:
            l=0
            b=0,
            w=self.width
            h=self.height
        rows, cols, image_str = im.as_rgba_str()
        image_array = np.fromstring(image_str, np.uint8)
        image_array.shape = rows, cols, 4
        bitmap = wx.BitmapFromBufferRGBA(cols,rows,image_array)
        gc = self.get_gc()
        gc.select()
        gc.gfx_ctx.DrawBitmap(bitmap,int(l),int(self.height-b),int(w),int(-h))
        gc.unselect() 
Example #5
Source File: backend_wxagg.py    From Computable with MIT License 5 votes vote down vote up
def _convert_agg_to_wx_bitmap(agg, bbox):
    """
    Convert the region of the agg buffer bounded by bbox to a wx.Bitmap.  If
    bbox is None, the entire buffer is converted.

    Note: agg must be a backend_agg.RendererAgg instance.
    """
    if bbox is None:
        # agg => rgba buffer -> bitmap
        return wx.BitmapFromBufferRGBA(int(agg.width), int(agg.height),
            agg.buffer_rgba())
    else:
        # agg => rgba buffer -> bitmap => clipped bitmap
        return _WX28_clipped_agg_as_bitmap(agg, bbox) 
Example #6
Source File: backend_wxagg.py    From Computable with MIT License 5 votes vote down vote up
def _WX28_clipped_agg_as_bitmap(agg, bbox):
    """
    Convert the region of a the agg buffer bounded by bbox to a wx.Bitmap.

    Note: agg must be a backend_agg.RendererAgg instance.
    """
    l, b, width, height = bbox.bounds
    r = l + width
    t = b + height

    srcBmp = wx.BitmapFromBufferRGBA(int(agg.width), int(agg.height),
        agg.buffer_rgba())
    srcDC = wx.MemoryDC()
    srcDC.SelectObject(srcBmp)

    destBmp = wx.EmptyBitmap(int(width), int(height))
    destDC = wx.MemoryDC()
    destDC.SelectObject(destBmp)

    destDC.BeginDrawing()
    x = int(l)
    y = int(int(agg.height) - t)
    destDC.Blit(0, 0, int(width), int(height), srcDC, x, y)
    destDC.EndDrawing()

    srcDC.SelectObject(wx.NullBitmap)
    destDC.SelectObject(wx.NullBitmap)

    return destBmp 
Example #7
Source File: backend_wxagg.py    From matplotlib-4-abaqus with MIT License 5 votes vote down vote up
def _convert_agg_to_wx_bitmap(agg, bbox):
    """
    Convert the region of the agg buffer bounded by bbox to a wx.Bitmap.  If
    bbox is None, the entire buffer is converted.

    Note: agg must be a backend_agg.RendererAgg instance.
    """
    if bbox is None:
        # agg => rgba buffer -> bitmap
        return wx.BitmapFromBufferRGBA(int(agg.width), int(agg.height),
            agg.buffer_rgba())
    else:
        # agg => rgba buffer -> bitmap => clipped bitmap
        return _WX28_clipped_agg_as_bitmap(agg, bbox) 
Example #8
Source File: backend_wxagg.py    From matplotlib-4-abaqus with MIT License 5 votes vote down vote up
def _WX28_clipped_agg_as_bitmap(agg, bbox):
    """
    Convert the region of a the agg buffer bounded by bbox to a wx.Bitmap.

    Note: agg must be a backend_agg.RendererAgg instance.
    """
    l, b, width, height = bbox.bounds
    r = l + width
    t = b + height

    srcBmp = wx.BitmapFromBufferRGBA(int(agg.width), int(agg.height),
        agg.buffer_rgba())
    srcDC = wx.MemoryDC()
    srcDC.SelectObject(srcBmp)

    destBmp = wx.EmptyBitmap(int(width), int(height))
    destDC = wx.MemoryDC()
    destDC.SelectObject(destBmp)

    destDC.BeginDrawing()
    x = int(l)
    y = int(int(agg.height) - t)
    destDC.Blit(0, 0, int(width), int(height), srcDC, x, y)
    destDC.EndDrawing()

    srcDC.SelectObject(wx.NullBitmap)
    destDC.SelectObject(wx.NullBitmap)

    return destBmp 
Example #9
Source File: backend_wxagg.py    From neural-network-animation with MIT License 5 votes vote down vote up
def _convert_agg_to_wx_bitmap(agg, bbox):
    """
    Convert the region of the agg buffer bounded by bbox to a wx.Bitmap.  If
    bbox is None, the entire buffer is converted.

    Note: agg must be a backend_agg.RendererAgg instance.
    """
    if bbox is None:
        # agg => rgba buffer -> bitmap
        return wx.BitmapFromBufferRGBA(int(agg.width), int(agg.height),
            agg.buffer_rgba())
    else:
        # agg => rgba buffer -> bitmap => clipped bitmap
        return _WX28_clipped_agg_as_bitmap(agg, bbox) 
Example #10
Source File: backend_wxagg.py    From neural-network-animation with MIT License 5 votes vote down vote up
def _WX28_clipped_agg_as_bitmap(agg, bbox):
    """
    Convert the region of a the agg buffer bounded by bbox to a wx.Bitmap.

    Note: agg must be a backend_agg.RendererAgg instance.
    """
    l, b, width, height = bbox.bounds
    r = l + width
    t = b + height

    srcBmp = wx.BitmapFromBufferRGBA(int(agg.width), int(agg.height),
        agg.buffer_rgba())
    srcDC = wx.MemoryDC()
    srcDC.SelectObject(srcBmp)

    destBmp = wx.EmptyBitmap(int(width), int(height))
    destDC = wx.MemoryDC()
    destDC.SelectObject(destBmp)

    destDC.BeginDrawing()
    x = int(l)
    y = int(int(agg.height) - t)
    destDC.Blit(0, 0, int(width), int(height), srcDC, x, y)
    destDC.EndDrawing()

    srcDC.SelectObject(wx.NullBitmap)
    destDC.SelectObject(wx.NullBitmap)

    return destBmp 
Example #11
Source File: three_to_four.py    From Gooey with MIT License 5 votes vote down vote up
def bitmapFromBufferRGBA(im, rgba):
    if isLatestVersion:
        return wx.Bitmap.FromBufferRGBA(im.size[0], im.size[1], rgba)
    else:
        return wx.BitmapFromBufferRGBA(im.size[0], im.size[1], rgba) 
Example #12
Source File: backend_wxagg.py    From ImageFusion with MIT License 5 votes vote down vote up
def _convert_agg_to_wx_bitmap(agg, bbox):
    """
    Convert the region of the agg buffer bounded by bbox to a wx.Bitmap.  If
    bbox is None, the entire buffer is converted.

    Note: agg must be a backend_agg.RendererAgg instance.
    """
    if bbox is None:
        # agg => rgba buffer -> bitmap
        return wx.BitmapFromBufferRGBA(int(agg.width), int(agg.height),
            agg.buffer_rgba())
    else:
        # agg => rgba buffer -> bitmap => clipped bitmap
        return _WX28_clipped_agg_as_bitmap(agg, bbox) 
Example #13
Source File: backend_wxagg.py    From ImageFusion with MIT License 5 votes vote down vote up
def _WX28_clipped_agg_as_bitmap(agg, bbox):
    """
    Convert the region of a the agg buffer bounded by bbox to a wx.Bitmap.

    Note: agg must be a backend_agg.RendererAgg instance.
    """
    l, b, width, height = bbox.bounds
    r = l + width
    t = b + height

    srcBmp = wx.BitmapFromBufferRGBA(int(agg.width), int(agg.height),
        agg.buffer_rgba())
    srcDC = wx.MemoryDC()
    srcDC.SelectObject(srcBmp)

    destBmp = wx.EmptyBitmap(int(width), int(height))
    destDC = wx.MemoryDC()
    destDC.SelectObject(destBmp)

    destDC.BeginDrawing()
    x = int(l)
    y = int(int(agg.height) - t)
    destDC.Blit(0, 0, int(width), int(height), srcDC, x, y)
    destDC.EndDrawing()

    srcDC.SelectObject(wx.NullBitmap)
    destDC.SelectObject(wx.NullBitmap)

    return destBmp 
Example #14
Source File: Icons.py    From EventGhost with GNU General Public License v2.0 5 votes vote down vote up
def CreateBitmapOnTopOfIcon(foregroundIcon, backgroundIcon, size=(12, 12)):
    small = foregroundIcon.pil.resize(size, Image.BICUBIC)
    pil = backgroundIcon.pil.copy()
    pil.paste(small, (16 - size[0], 16 - size[1]), small)
    return wx.BitmapFromBufferRGBA(pil.size[0], pil.size[1], str(pil.tobytes())) 
Example #15
Source File: Icons.py    From EventGhost with GNU General Public License v2.0 5 votes vote down vote up
def PilToBitmap(pil):
    """
    Convert a PIL image to a wx.Bitmap (with alpha channel support).
    """
    return wx.BitmapFromBufferRGBA(pil.size[0], pil.size[1], str(pil.tobytes()))

# setup some commonly used icons