def MakeLutImage(self, size=None): if size is None: w, h = self.GetClientSize() else: w, h = size s = self.LutData.get_lut(self.lut_index) so = np.zeros(256, dtype=np.uint8) so.fill(255) image = wx.EmptyImage(256, 1) image.SetData(s) image.SetAlphaData(so.tostring()) self.img_lut = image
def GetBitmap_from_np_array(np_img_2d): fig = plt.figure() # remember to make sure this is our convention in (x, y) vs (row, col) plt.imshow(numpy.transpose(np_img_2d), interpolation="nearest") fig.canvas.draw() width, height = fig.canvas.get_width_height() np_buf = numpy.fromstring(fig.canvas.tostring_rgb(), dtype=numpy.uint8) np_buf.shape = (width, height, 3) np_buf = numpy.roll(np_buf, 3, axis=2) image = wx.EmptyImage(width, height) image.SetData(np_buf) # image.SetData( np_buf.tostring()) # looks like there is no need to convert wxBitmap = image.ConvertToBitmap() return wxBitmap
def __init__(self, monitor = 1, isImageLock = True): self.isImageLock = isImageLock # Create the frame #wx.Frame.__init__(self,None,-1,'SLM window',pos = (self._x0, self._y0), size = (self._resX, self._resY)) self.SetMonitor(monitor) # Set the frame to the position and size of the target monito wx.Frame.__init__(self,None,-1,'SLM window',pos = (self._x0, self._y0), size = (self._resX, self._resY)) self.img = wx.EmptyImage(2,2) self.bmp = self.img.ConvertToBitmap() self.clientSize = self.GetClientSize() # Update the image upon receiving an event EVT_NEW_IMAGE self.Bind(EVT_NEW_IMAGE, self.UpdateImage) # Set full screen self.ShowFullScreen(not self.IsFullScreen(), wx.FULLSCREEN_ALL) self.SetFocus()
def CreationImage(self, tailleImages, r, v, b, IDcategorie): """ Création des images pour le TreeCtrl """ colFond = couleurFondWidgets if 'phoenix' in wx.PlatformInfo: bmp = wx.Image(tailleImages[0], tailleImages[1], True) bmp.SetRGB((0, 0, 16, 16), colFond[0], colFond[1], colFond[2]) bmp.SetRGB((3, 3, 10, 10), 0, 0, 0) bmp.SetRGB((4, 4, 8, 8), r, v, b) else: bmp = wx.EmptyImage(tailleImages[0], tailleImages[1], True) bmp.SetRGBRect((0, 0, 16, 16), colFond[0], colFond[1], colFond[2]) bmp.SetRGBRect((3, 3, 10, 10), 0, 0, 0) bmp.SetRGBRect((4, 4, 8, 8), r, v, b) return bmp.ConvertToBitmap()
def __init__(self, frm): #__init__(self, String name, long type=BITMAP_TYPE_ANY, int index=-1) #self.widget=wx.Image("/home/nchy13/Desktop/1.png",BITMAP_TYPE_ANY,-1) #self.widget.Create(100,200,clear=True) self.panel = frm.panel #self.bit=wx.Bitmap(path) #self.depth=self.bit.GetDepth() #self.height=self.bit.GetHeight() self.PhotoMaxSize = 500 self.img = wx.EmptyImage(550, 550) self.inter = wx.BitmapFromImage(self.img) self.widget = wx.StaticBitmap(frm.panel, -1, self.inter)
def __init__(self, parent, id, img): wx.Panel.__init__(self, parent, id) self.SetBackgroundColour("white") # Make a non-transparend image with white background background = Image.new("RGB", img.size, (255,255,255)) background.paste(img, mask=img.split()[3]) wximg = wx.EmptyImage(*background.size) wximg.SetData(background.convert('RGB').tobytes()) wxbmp = wx.BitmapFromImage(wximg) sizer = wx.BoxSizer() self.img_control = wx.StaticBitmap(self, -1, wxbmp, (0,0)) sizer.Add(self.img_control, 1, wx.EXPAND) self.SetSizer(sizer) sizer.Fit(parent)
def layout(self): """ Layout the widgets on the panel """ self.mainSizer = wx.GridSizer(rows=1, cols=1, hgap=5, vgap=5) self.images = [] 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.ALIGN_CENTER, 5) self.SetSizer(self.mainSizer)
def ConvertTailleImage(self, bitmap=None, taille=None): """ Convertit la taille d'une image """ if 'phoenix' in wx.PlatformInfo: img = wx.Image(taille[0], taille[1], True) img.SetRGB((0, 0, taille[0], taille[1]), 255, 255, 255) else: img = wx.EmptyImage(taille[0], taille[1], True) img.SetRGBRect((0, 0, taille[0], taille[1]), 255, 255, 255) bmp = img.ConvertToBitmap() dc = wx.MemoryDC() dc.SelectObject(bmp) dc.DrawBitmap(bitmap, taille[0] / 2.0 - bitmap.GetSize()[0] / 2.0, taille[1] / 2.0 - bitmap.GetSize()[1] / 2.0) dc.SelectObject(wx.NullBitmap) return bmp
def SetwxImageData(numpyarray): """ #本程序将numpyarray的数据加载到wxImage中 #numpyarray一般从文件中读取 #>>from matplotlib.pyplot import imread #>>numpyarray=imread(filename) #numpyarray必须是2维灰度图像或3维数组(R,G,B) #本程序的作用是可以将修改后的numpyarray加载到image中 """ import array nasize = len(numpyarray.shape) #测试数组的位数 if nasize == 2: Height, Width = numpyarray.shape wximage = wx.EmptyImage(Width, Height) Data = numpy.empty([Height, Width, 3], dtype='byte') Data[:, :, 0] = numpyarray Data[:, :, 1] = numpyarray Data[:, :, 2] = numpyarray wximage.SetData(numpy.flipud(Data).tostring()) elif nasize == 3: Height, Width, dim = numpyarray.shape wximage = wx.EmptyImage(Width, Height) if dim == 3: #保存的是(R,G,B) #注意下面的代码,一定要将numpyarray上下反转一下 wximage.SetData(numpy.flipud(numpyarray).tostring()) elif dim == 4: #某些格式,较少见 Data = numpy.empty([Height, Width, 3], dtype='byte') Data[:, :, :] = numpyarray[:, :, 0:3] wximage.SetData(numpy.flipud(Data).tostring()) elif dim == 1: #其实仍然是灰度图像 Data = numpy.empty([Height, Width, 3], dtype='byte') Data[:, :, 0] = numpyarray[:, :, 0] Data[:, :, 1] = numpyarray[:, :, 0] Data[:, :, 2] = numpyarray[:, :, 0] wximage.SetData(numpy.flipud(Data).tostring()) return wximage
def __MakeCursor(data): img = wx.EmptyImage(16, 16) img.SetMaskColour(255, 0, 0) for px in range(len(data)): for py in range(len(data[px])): val = data[px][py] if val == 2: img.SetRGB(px, py, 255, 0, 0) elif val == 1: img.SetRGB(px, py, 0, 0, 0) elif val == 0: img.SetRGB(px, py, 255, 255, 255) img.SetOptionInt(wx.IMAGE_OPTION_CUR_HOTSPOT_X, 8) img.SetOptionInt(wx.IMAGE_OPTION_CUR_HOTSPOT_Y, 8) return wx.CursorFromImage(img)
def padpiltoimage(pil, width, height, alpha=True): """Convert PIL Image to wx.Image.""" output = Image.new("RGBA", (width, height)) output.paste(pil, ((width - pil.size[0]) / 2, (height - pil.size[1]) / 2)) if alpha: image = apply(wx.EmptyImage, (output.size[0], output.size[1])) image.SetData(output.convert("RGB").tostring()) image.SetAlphaData(output.convert("RGBA").tostring()[3::4]) else: image = wx.EmptyImage(output.size[0], output.size[1]) new_image = output.convert('RGB') data = new_image.tostring() image.SetData(data) return image
def _convert_agg_to_wx_image(agg, bbox): """ Convert the region of the agg buffer bounded by bbox to a wx.Image. If bbox is None, the entire buffer is converted. Note: agg must be a backend_agg.RendererAgg instance. """ if bbox is None: # agg => rgb -> image image = wx.EmptyImage(int(agg.width), int(agg.height)) image.SetData(agg.tostring_rgb()) return image else: # agg => rgba buffer -> bitmap => clipped bitmap => image return wx.ImageFromBitmap(_WX28_clipped_agg_as_bitmap(agg, bbox))
def __init__(self, parent,title, sock): wx.Frame.__init__(self, parent,title=title, size=(1200,750)) self.SetCursor(wx.StockCursor(wx.CURSOR_PENCIL)) self.panel = wx.Panel(self) self.panel.SetSize((1180,620)) self.myWxImage = wx.EmptyImage( 1180, 620 ) self.imageCtrl = wx.StaticBitmap(self.panel,wx.ID_ANY,wx.BitmapFromImage(self.myWxImage)) self.NH=0 self.NW=0 # hook some mouse events self.imageCtrl.Bind(wx.EVT_LEFT_DOWN, lambda event,sock = sock : self.OnLeftDown(event,sock)) self.imageCtrl.Bind(wx.EVT_RIGHT_DOWN, lambda event,sock = sock : self.OnRightDown(event,sock)) self.imageCtrl.Bind(wx.EVT_LEFT_DCLICK, lambda event,sock = sock : self.OnLeftDouble(event,sock)) self.imageCtrl.Bind(wx.EVT_KEY_DOWN, lambda event,sock = sock : self.self.OnKeyPress(event,sock)) self.Show(True)
def CreateImageView(self): if self.dev != None: pil = screenshot(self.dev.id) else: bgcolor = (192,192,192) pil = Image.new('RGB',(360,640),bgcolor) image = wx.EmptyImage(pil.size[0], pil.size[1]) image.SetData(pil.convert('RGB').tostring()) assert image.IsOk()== True y = image.GetHeight() self.scale = 640.0/y rescale = image.Rescale(360 ,640) new_png = rescale.ConvertToBitmap() self.screenshot = wx.StaticBitmap(self, -1, new_png, (0, 0), (new_png.GetWidth(), new_png.GetHeight())) return self.screenshot
def SetLutIndex(self, lut_index, redraw=1): self.lut_index = lut_index s = self.LutData.get_lut(lut_index) image = wx.EmptyImage(256, 1) image.SetData(s) self.img = image self.MakeLutImage() w, h = self.GetClientSize() if 1: # FIXME this causes problems!! if self.histo_image is None: self.buffer = wx.EmptyBitmapRGBA(w, h, 0, 0, 0, 1) else: img = wx.EmptyImage(1, 1) img.SetData("\xff\xff\xff") img_scaled = img.Scale(w, h) self.buffer = img_scaled.ConvertToBitmap() if redraw: self.UpdateDrawing()
def GetBitmap_from_np_array(data2d): lc_fig = plt.figure(frameon=False) xmax = len(data2d[:, 1]) ymax = len(data2d[1, :]) vl_max = np.amax(data2d) vl_min = np.amin(data2d) d = vl_max - vl_min vl_mid_low = vl_min + d / 3.0 vl_mid_hig = vl_max - d / 3.0 lc_fig.set_size_inches(xmax * 0.6, ymax * 0.6) # lc_fig.set_size_inches(xmax * .2, ymax * .2) ax = plt.Axes(lc_fig, [0.0, 0.0, 1.0, 1.0]) ax.set_axis_off() lc_fig.add_axes(ax) plt.imshow(np.transpose(data2d), interpolation="nearest", cmap="hot") # print "xmax =", xmax # print "ymax =", ymax for xpos in range(xmax): for ypos in range(ymax): f_num = data2d[xpos, ypos] g = float("{0:.2f}".format(float(f_num))) txt_dat = str(g) if g < vl_mid_low: clr_chr = "yellow" elif g > vl_mid_hig: clr_chr = "black" else: clr_chr = "blue" # plt.annotate(txt_dat, xy = (xpos - 0.3, ypos + 0.3), xycoords = 'data' # , color = clr_chr, size = 12.) lc_fig.canvas.draw() width, height = lc_fig.canvas.get_width_height() np_buf = np.fromstring(lc_fig.canvas.tostring_rgb(), dtype=np.uint8) np_buf.shape = (width, height, 3) np_buf = np.roll(np_buf, 3, axis=2) wx_image = wx.EmptyImage(width, height) wx_image.SetData(np_buf) wxBitmap = wx_image.ConvertToBitmap() plt.close(lc_fig) return wxBitmap
def updateLatestImage(self, event=None, fade=False): oldMode = self.config['imageMode'] if getattr(self, "wxLatestImage", None) is None: self.latestImageTime = time.time() self.loadLatestImage() if self.config['enableFade']: self.pilLatestImageOld = self.pilLatestImage if time.time() - self.latestImageTime > 5: self.latestImageTime = time.time() if self.config['enableFade']: self.pilLatestImageOld = self.pilLatestImage self.loadLatestImage() if self.config['enableFade']: if time.time() - self.pilLatestImageTime < self.config['fadeTime']: alpha = (time.time() - self.pilLatestImageTime) / self.config['fadeTime'] try: pilImage = PImage.blend(self.pilLatestImageOld, self.pilLatestImage, alpha) pilImage = pilImage.convert('RGB') except ValueError: pilImage = self.pilLatestImage else: pilImage = self.pilLatestImage # Convert to wxImage wxImage = wx.EmptyImage(*pilImage.size) wxImage.SetData(pilImage.tostring()) else: wxImage = self.wxLatestImage w, h = self._keepAspect(wxImage, self.latestImage) image = wxImage.Scale(w, h, self.config['imageQuality']) w2, h2 = self.latestImage.GetSize() image.Resize(self.latestImage.GetSize(), ((w2 - w) / 2, (h2 - h) / 2), 0, 0, 0) bitmap = Bitmap(image) dc = ClientDC(self.latestImage) dc.DrawBitmap(bitmap, 0, 0) if oldMode != self.config['imageMode']: if self.config['verbose']: print "Image mode changed, triggering description update" wx.CallAfter(self.updateImageDescription)
def drawBkg(self): if self.bw: self.bkgclr = (255,255,255) else: self.bkgclr = self.options.clrbackground self.SetBackgroundColour(self.bkgclr) tableclr = self.options.clrtable if self.bw: tableclr = (0,0,0) img = Image.new('RGB', (self.WIDTH, self.HEIGHT), self.bkgclr) draw = ImageDraw.Draw(img) BOR = commonwnd.CommonWnd.BORDER txtclr = (0,0,0) if not self.bw: txtclr = self.options.clrtexts #Title draw.rectangle(((BOR+self.SMALL_CELL_WIDTH, BOR),(BOR+self.SMALL_CELL_WIDTH+self.TITLE_WIDTH, BOR+self.TITLE_HEIGHT)), outline=(tableclr), fill=(self.bkgclr)) txt = mtexts.txts['HousePercent'] w,h = draw.textsize(txt, self.fntText) draw.text((BOR+self.SMALL_CELL_WIDTH+(self.CELL_WIDTH-w)/2, BOR+(self.TITLE_HEIGHT-h)/2), txt, fill=txtclr, font=self.fntText) x = BOR y = BOR+self.TITLE_HEIGHT+self.SPACE_TITLEY draw.line((x, y, x+self.TABLE_WIDTH, y), fill=tableclr) ii = 0 for i in range(len(common.common.Planets)-1): if self.options.intables and ((i == astrology.SE_URANUS and not self.options.transcendental[chart.Chart.TRANSURANUS]) or (i == astrology.SE_NEPTUNE and not self.options.transcendental[chart.Chart.TRANSNEPTUNE]) or (i == astrology.SE_PLUTO and not self.options.transcendental[chart.Chart.TRANSPLUTO]) or (i == astrology.SE_MEAN_NODE and not self.options.shownodes)): continue self.drawline(draw, x, y+ii*self.LINE_HEIGHT, tableclr, i) ii += 1 #Arabian Parts if not self.options.intables or (self.options.intables and self.options.showlof): x = BOR y = BOR+self.TITLE_HEIGHT+self.SPACE_TITLEY+(self.LINE_NUM)*(self.LINE_HEIGHT)+self.SPACE_ARABIANY draw.rectangle(((x,y),(x+self.TITLE_WIDTH_ARABIAN, y+self.LINE_HEIGHT)), outline=(tableclr), fill=(self.bkgclr)) self.drawlinelof(draw, x, y, mtexts.txts['MLoF'], self.chart.munfortune.mfortune, tableclr, 0) wxImg = wx.EmptyImage(img.size[0], img.size[1]) wxImg.SetData(img.tostring()) self.buffer = wx.BitmapFromImage(wxImg)
def pilToBitmap(pil, scaleFactor=1.0): if parse_version(wx.__version__) < parse_version('4.0.0a1'): image = wx.EmptyImage(pil.size[0], pil.size[1]) else: image = wx.Image(pil.size[0], pil.size[1]) # set the RGB values if hasattr(pil, 'tobytes'): image.SetData(pil.convert("RGB").tobytes()) image.SetAlphaBuffer(pil.convert("RGBA").tobytes()[3::4]) else: image.SetData(pil.convert("RGB").tostring()) image.SetAlphaData(pil.convert("RGBA").tostring()[3::4]) image.Rescale(image.Width * scaleFactor, image.Height * scaleFactor) return image.ConvertToBitmap() # wx.Image and wx.Bitmap are different
def startPreview(self, iPreview, fps=5): self.__iPreview = iPreview dc = wx.BufferedPaintDC(self) self.__dcWidth, self.__dcHeight = dc.GetSize() del dc self.__bmp = wx.EmptyBitmap(self.__dcWidth, self.__dcHeight, 24) self.__img = wx.EmptyImage(self.__dcWidth, self.__dcHeight) self.Bind(wx.EVT_PAINT, self.__onPaint) self.Bind(wx.EVT_TIMER, self.__nextFrame) iPreview.onPreviewInit() self.__timer = wx.Timer(self) self.__timer.Start(1000. / fps)
def onBlur(self, event): matriz = np.matrix([[0.0, 0.2, 0.0], [0.2, 0.2, 0.2], [0.0, 0.2, 0.0]]) factor, ajuste = 1.0, 0.0 img = self.convolucion(matriz, factor, ajuste) # Conversion image = wx.EmptyImage(img.size[0], img.size[1]) new_image = img.convert('RGB') data = new_image.tobytes() image.SetData(data) # Fin conversion fgs = wx.FlexGridSizer(cols=1, hgap=10, vgap=10) sb1 = wx.StaticBitmap(self.panel, -1, wx.BitmapFromImage(image)) fgs.Add(sb1) self.panel.SetSizerAndFit(fgs) self.Fit() self.Refresh()
def PaneCreateStippleBitmap(): """ Creates a stipple bitmap to be used in a `wx.Brush`. This is used to draw sash resize hints. """ data = [0, 0, 0, 192, 192, 192, 192, 192, 192, 0, 0, 0] img = wx.EmptyImage(2, 2) counter = 0 for ii in xrange(2): for jj in xrange(2): img.SetRGB(ii, jj, data[counter], data[counter+1], data[counter+2]) counter = counter + 3 return img.ConvertToBitmap()
def __init__(self, parent, id=-1, style=wx.FULL_REPAINT_ON_RESIZE): wx.Window.__init__(self, parent, id, style=style) self.timer = wx.Timer self.img = wx.EmptyImage(2, 2) self.bmp = self.img.ConvertToBitmap() self.clientSize = self.GetClientSize() self.Bind(wx.EVT_PAINT, self.OnPaint) #For video support #------------------------------------------------------------ self.Bind(EVT_NEW_IMAGE, self.OnNewImage) self.eventLock = None self.pause = False
def OnLaunch(self, evt): if not self.actif: if not self.captcha_selected: wx.MessageBox("Selectionner le Captcha !", "Donnee manquante") return if not self.model_selected: wx.MessageBox("Selectionner le modele SVM !", "Donnee manquante") return self.actif = not self.actif self.launchButton.SetLabel("Arreter le calcul") thread.start_new_thread(Break_Captcha_util.break_captcha, (self.model, self.captcha, self.width_picker.GetValue(), self, self.graph_image)) else: self.launchButton.SetLabel("Relancer le calcul") self.graph_image = wx.EmptyImage(127,31) self.actif = not self.actif
def draw_to_wxwindow(self, window, x, y): import wx window_dc = getattr(window, "_dc", None) if window_dc is None: window_dc = wx.PaintDC(window) arr = self.convert_to_rgbarray() image = wx.EmptyImage(self.width, self.height) image.SetDataBuffer(arr.data) bmp = wx.BitmapFromImage(image, depth=-1) # Scale HiDPI images to fit window bmp.SetSize(window.GetSize()) window_dc.BeginDrawing() window_dc.DrawBitmap(bmp, x, y) window_dc.EndDrawing()
def OnLaunchPrediction(self, evt): if not self.actif: if not self.captcha_selected: wx.MessageBox("Selectionner le Captcha !", "Donnee manquante") return if not self.model_selected: wx.MessageBox("Selectionner le modele SVM !", "Donnee manquante") #return self.actif = not self.actif self.launchPredictionButton.SetLabel("Arreter le calcul") thread.start_new_thread(Hotmail_5_ComputeScores.get_prediction, (self.model, self.captcha, self)) else: self.launchPredictionButton.SetLabel("Relancer le calcul") self.graph_image = wx.EmptyImage(127,31) self.actif = not self.actif
def get_polyregion(points, w, h, border=1): i = wx.EmptyImage(w + border, h + border) b = i.WXB m = wx.MemoryDC(b) m.Clear() m.SetBrush(wx.Brush(wx.Color(0,0,0))) m.SetPen(wx.Pen(wx.Color(0,0,0))) #ceil(border/2)? m.DrawRectangle(0,0,w + border, h + border) m.SetBrush(wx.Brush(wx.Color(255,255,255))) m.SetPen(wx.Pen(wx.Color(255,255,255))) m.DrawPolygon(points) m.SelectObject(wx.NullBitmap) del m b.SetMaskColour(wx.Color(0,0,0)) return wx.RegionFromBitmap(b)
def ConvertTailleImage(self, bitmap=None, taille=None): """ Convertit la taille d'une image """ # Réduction de l'image bitmap = bitmap.ConvertToImage() bitmap = bitmap.Rescale(width=taille[0], height=taille[1], quality=wx.IMAGE_QUALITY_HIGH) bitmap = bitmap.ConvertToBitmap() # Insertion de l'image sur un fond noir img = wx.EmptyImage(taille[0], taille[1], True) img.SetRGBRect((0, 0, taille[0], taille[1]), 0, 0, 0) bmp = img.ConvertToBitmap() dc = wx.MemoryDC() dc.SelectObject(bmp) dc.DrawBitmap(bitmap, taille[0]/2.0-bitmap.GetSize()[0]/2.0, taille[1]/2.0-bitmap.GetSize()[1]/2.0) dc.SelectObject(wx.NullBitmap) return bmp
def GetPolyRegion(points, w, h, border=1): i = wx.EmptyImage(w + border, h + border) b = wx.BitmapFromImage(i) m = wx.MemoryDC(b) m.Clear() m.SetBrush(wx.BLACK_BRUSH) m.SetPen(wx.BLACK_PEN) m.DrawRectangle(0, 0, w + border, h + border) m.SetBrush(wx.WHITE_BRUSH) m.SetPen(wx.Pen(wx.WHITE)) m.DrawPolygon(points) m.SelectObject(wx.NullBitmap) b.SetMask(wx.Mask(b, wx.BLACK)) return wx.RegionFromBitmap(b)
def __init__(self, title, size): wx.App.__init__(self, redirect=False) self.AppName = "Odemis CLI" self.frame = wx.Frame(None, title=title, size=size) self.panel = wx.Panel(self.frame) self.panel.Bind(wx.EVT_KEY_DOWN, self.OnKey) # just in case panel doesn't have the focus: also on the frame # (but it seems in Linux (GTK) frames don't receive key events anyway self.frame.Bind(wx.EVT_KEY_DOWN, self.OnKey) self.img = wx.EmptyImage(*size, clear=True) self.imageCtrl = wx.StaticBitmap(self.panel, wx.ID_ANY, wx.BitmapFromImage(self.img)) self.panel.SetFocus() self.frame.Show()