我们从Python开源项目中,提取了以下16个代码示例,用于说明如何使用wx.EmptyImage()。
def UpdateImage2D(self): object = self.object imagedata = numpy.array(object, dtype=numpy.double) imagedata[imagedata < 1e-6] = 1.0 imagedata = numpy.log(imagedata) imagedata = imagedata - imagedata.min() if imagedata.max() > 0: imagedata = (255.0/imagedata.max())*imagedata else: imagedata = 255.0*imagedata imagedatalow = numpy.uint8(imagedata) self.impil = Image.fromarray(imagedatalow, 'L').resize((self.sx,self.sy)) self.imwx = wx.EmptyImage( self.impil.size[0], self.impil.size[1] ) self.imwx.SetData( self.impil.convert( 'RGB' ).tobytes() ) bitmap = wx.BitmapFromImage(self.imwx) self.bmp = bitmap self.image.SetBitmap(bitmap) self.Refresh() self.Layout()
def graph_caps(self, cap_files, graphdir): OS = "linux" if len(cap_files) > 1: print("make caps graph") if OS == "linux": print("Yay linux") os.system("../visualisation/caps_graph.py caps="+capsdir+" out="+graphdir) elif OS == 'win': print("oh, windows, i prefer linux but no worries...") os.system("python ../visualisation/caps_graph.py caps="+capsdir+" out="+graphdir) else: print("skipping graphing caps - disabled or no caps to make graphs with") if os.path.exists(graphdir+'caps_filesize_graph.png'): cap_size_graph_path = wx.Image(graphdir+'caps_filesize_graph.png', wx.BITMAP_TYPE_ANY) return cap_size_graph_path else: print("NOT ENOUGH CAPS GRAPH SO USING BLANK THUMB") blankimg = wx.EmptyImage(width=100, height=100, clear=True) return blankimg
def layout(self): """ Layout the widgets on the panel """ self.mainSizer = wx.BoxSizer(wx.VERTICAL) btnSizer = wx.BoxSizer(wx.HORIZONTAL) img = wx.EmptyImage(self.photoMaxSize,self.photoMaxSize) self.imageCtrl = wx.StaticBitmap(self, wx.ID_ANY, wx.BitmapFromImage(img)) self.mainSizer.Add(self.imageCtrl, 0, wx.ALL|wx.CENTER, 5) self.imageLabel = wx.StaticText(self, label="") self.mainSizer.Add(self.imageLabel, 0, wx.ALL|wx.CENTER, 5) btnData = [("Previous", btnSizer, self.onPrevious), ("Slide Show", btnSizer, self.onSlideShow), ("Next", btnSizer, self.onNext)] for data in btnData: label, sizer, handler = data self.btnBuilder(label, sizer, handler) self.mainSizer.Add(btnSizer, 0, wx.CENTER) self.SetSizer(self.mainSizer)
def Get(self,l,r): s=""+self.s_line for i in range(5): if i<(5-l): sl = self.sl_off else: sl = self.sl_on if i<(5-r): sr = self.sr_off else: sr = self.sr_on s+=self.s_border+sl+self.s_point+sr+self.s_point s+=self.s_border+sl+self.s_point+sr+self.s_point s+=self.s_line image = wx.EmptyImage(16,16) image.SetData(s) bmp = image.ConvertToBitmap() bmp.SetMask(wx.Mask(bmp, wx.WHITE)) #sets the transparency colour to white icon = wx.EmptyIcon() icon.CopyFromBitmap(bmp) return icon ## # The TaskBarIcon class #
def UpdateImage(self, axis, position): object = self.object idx = position - 1 if axis == 1: imagedata = object[idx,:,:] elif axis == 2: imagedata = object[:,idx,:] else: imagedata = object[:,:,idx] imagedata[imagedata < 1e-6] = 1.0 imagedata = numpy.log(imagedata) imagedata = imagedata - imagedata.min() if imagedata.max() > 0: imagedata = (255.0/imagedata.max())*imagedata else: imagedata = 255.0*imagedata imagedatalow = numpy.uint8(imagedata) self.impil = Image.fromarray(imagedatalow, 'L').resize((self.sx,self.sy)) if IsNotWX4(): self.imwx = wx.EmptyImage( self.impil.size[0], self.impil.size[1] ) else: self.imwx = wx.Image( self.impil.size[0], self.impil.size[1] ) self.imwx.SetData( self.impil.convert( 'RGB' ).tobytes() ) if IsNotWX4(): bitmap = wx.BitmapFromImage(self.imwx) else: bitmap = wx.Bitmap(self.imwx) if IsNotWX4(): self.bmp = wx.BitmapFromImage(self.imwx) else: self.bmp = wx.Bitmap(self.imwx) self.image.SetBitmap(bitmap) self.Refresh() self.Layout()
def UpdateImage(self, axis, position): object = self.object idx = position - 1 if axis == 1: imagedata = numpy.array(object[idx,:,:]) elif axis == 2: imagedata = numpy.array(object[:,idx,:]) else: imagedata = numpy.array(object[:,:,idx]) imagedata[imagedata < 1e-6] = 1.0 imagedata = numpy.log(imagedata) imagedata = imagedata - imagedata.min() if imagedata.max() > 0: imagedata = (255.0/imagedata.max())*imagedata else: imagedata = 255.0*imagedata imagedatalow = numpy.uint8(imagedata) self.impil = Image.fromarray(imagedatalow, 'L').resize((self.sx,self.sy)) if IsNotWX4(): self.imwx = wx.EmptyImage( self.impil.size[0], self.impil.size[1] ) else: self.imwx = wx.Image( self.impil.size[0], self.impil.size[1] ) self.imwx.SetData( self.impil.convert( 'RGB' ).tobytes() ) if IsNotWX4(): bitmap = wx.BitmapFromImage(self.imwx) else: bitmap = wx.Bitmap(self.imwx) self.bmp = bitmap self.image.SetBitmap(bitmap) self.Refresh() self.Layout()
def __init__(self, parent): self.panel = wx.ScrolledWindow.__init__(self, parent) self.SetScrollRate(5, 5) self.panelphase = self.GetParent().panelphase self.panelvisual = self.GetParent().panelvisual self.cmvbox = wx.BoxSizer(wx.VERTICAL) self.cmhbox = [] self.imglist = [] self.sellist = [] self.rb = [] self.chkb = [] array = self.panelphase.cms[0][1] dc = wx.ScreenDC() dc.SetFont(self.panelvisual.font) w,h = dc.GetTextExtent("TestString") height = h if IsNotWX4(): image = wx.EmptyImage(array.shape[0],height) else: image = wx.Image(array.shape[0],height) newarray = numpy.zeros((height, array.shape[0], 3), dtype=numpy.uint8) for i in range(self.panelphase.cms.shape[0]): self.cmhbox.append( wx.BoxSizer(wx.HORIZONTAL) ) name = self.panelphase.cms[i][0] array = self.panelphase.cms[i][1] for j in range(height): newarray[j,:,:] = numpy.uint8(255.0*array) image.SetData( newarray.tostring()) bmp = image.ConvertToBitmap() self.imglist.append(wx.StaticBitmap(self, -1, bmp)) self.rb.append( wx.RadioButton(self, -1, label=name, size=(160, height) ) ) self.cmhbox[-1].Add(self.rb[-1], 0) self.cmhbox[-1].Add((5, -1)) self.cmhbox[-1].Add(self.imglist[-1], 1, wx.EXPAND) self.chkb.append( wx.CheckBox(self, -1, 'Reverse', size=(160, height)) ) self.cmhbox[-1].Add(self.chkb[-1], 0, wx.EXPAND) self.cmvbox.Add(self.cmhbox[-1], 1, wx.EXPAND) self.SetSizer(self.cmvbox) self.Fit() self.Layout() self.Show()
def OnSize(self, event): # The Buffer init is done here, to make sure the buffer is always # the same size as the Window Size = self.canvas.GetClientSize() if Size.width <= 0 or Size.height <= 0: return Size.width = max(1, Size.width) Size.height = max(1, Size.height) # Make new offscreen bitmap: this bitmap will always have the # current drawing in it, so it can be used to save the image to # a file, or whatever. #self._Buffer = wx.Bitmap(Size.width, Size.height) if IsNotWX4(): self._img = wx.EmptyImage(Size.width,Size.height) self._Buffer = wx.BitmapFromImage(self._img) else: self._img = wx.Image(Size.width,Size.height) self._Buffer = wx.Bitmap(self._img) self._Buffer.SetHeight(Size.height) self._Buffer.SetWidth(Size.width) self._setSize() self.last_PointLabel = None # reset pointLabel if self.last_draw is None: self.Clear() else: graphics, xSpec, ySpec = self.last_draw self._Draw(graphics, xSpec, ySpec)
def ConvertWXToPIL(self, bmp): """ Convert wx.Image Into PIL Image. """ width = bmp.GetWidth() height = bmp.GetHeight() im = wx.EmptyImage(width, height) im.fromarray("RGBA", (width, height), bmp.GetData()) return im # ------------------------------------------------------------ # ImFrame.ConvertPILToWX() # Expropriated from Andrea Gavana's # ShapedButton.py in the wxPython dist # ------------------------------------------------------------
def ConvertPILToWX(self, pil, alpha=True): """ Convert PIL Image Into wx.Image. """ if alpha: image = wx.EmptyImage(*pil.size) image.SetData(pil.convert("RGB").tostring()) image.SetAlphaData(pil.convert("RGBA").tostring()[3::4]) else: image = wx.EmptyImage(pil.size[0], pil.size[1]) new_image = pil.convert('RGB') data = new_image.tostring() image.SetData(data) return image
def saveImageGL(mvcanvas, filename): view = glGetIntegerv(GL_VIEWPORT) img = wx.EmptyImage(view[2], view[3] ) pixels = glReadPixels(0, 0, view[2], view[3], GL_RGB, GL_UNSIGNED_BYTE) img.SetData( pixels ) img = img.Mirror(False) img.SaveFile(filename, wx.BITMAP_TYPE_PNG)
def piltowx(pil): wxi = wx.EmptyImage(*pil.size) wxi.SetData(pil.copy().convert('RGB').tobytes()) return wxi
def pil_image_to_wx_image(pil_image): """Convert from PIL image to wx image.""" wx_image = wx.EmptyImage(pil_image.width, pil_image.height) wx_image.SetData(pil_image.convert("RGB").tobytes()) return wx_image