def bitmapFromData(self, data): # get the data shape height, width, depth = data.shape # flatten to byte string flatdata = data.tostring() # create image of the right shape image = Image(width, height) # load image with byte string image.SetData(flatdata) # convert image to bitmap bitmap = image.ConvertToBitmap() # done return bitmap
def __init__(self, image: wx.Image = None, **kwargs): wx.Panel.__init__(self, **kwargs) self._f_data = None self._a_data = None self._f_fft_data = None self._a_fft_data = None self.set_default_data() bitmap = self.get_data_bitmap( ) if image is None else image.ConvertToBitmap() self.bmp = wx.StaticBitmap(parent=self, bitmap=bitmap, pos=(self.padding, self.padding)) self.SetMinSize((bitmap.GetWidth() + self.padding * 2, bitmap.GetHeight() + self.padding * 2)) self.Bind(wx.EVT_MOUSEWHEEL, self.on_mousewheel_scroll, self.bmp)
def wx_to_wxbit(img: wx.Image): ''' Converts a wx image to a wx bitmap ''' return img.ConvertToBitmap()
w, h, d = 2, 4, 3 data0 = zeros((h, w, 3), 'uint8') data0[:, :, ] = (10, 20, 30) print(data0) print('---') flatdata0 = data0.tostring() image0 = Image(w, h) image0.SetData(flatdata0) bitmap = image0.ConvertToBitmap() image1 = bitmap.ConvertToImage() flatdata1 = image1.GetData() lineardata = frombuffer(flatdata1, 'uint8') data1 = lineardata.reshape(h, w, 3) print(data1) print('---') # def bitmapFromData(self, data): # # get the data shape # height, width, depth = data.shape