Python wx.Image() Examples
The following are 30
code examples of wx.Image().
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: configuration_dialogs.py From superpaper with MIT License | 7 votes |
def create_thumb_bmp(self, filename): wximg = wx.Image(filename, type=wx.BITMAP_TYPE_ANY) imgsize = wximg.GetSize() w2h_ratio = imgsize[0]/imgsize[1] if w2h_ratio > 1: target_w = self.tsize[0] target_h = target_w/w2h_ratio pos = (0, round((target_w - target_h)/2)) else: target_h = self.tsize[1] target_w = target_h*w2h_ratio pos = (round((target_h - target_w)/2), 0) bmp = wximg.Scale(target_w, target_h, quality=wx.IMAGE_QUALITY_BOX_AVERAGE ).Resize(self.tsize, pos ).ConvertToBitmap() return bmp # # BUTTON methods #
Example #2
Source File: gui.py From reading-frustum-pointnets-code with Apache License 2.0 | 6 votes |
def OnSelect(self, event): wildcard = "image source(*.jpg)|*.jpg|" \ "Compile Python(*.pyc)|*.pyc|" \ "All file(*.*)|*.*" dialog = wx.FileDialog(None, "Choose a file", os.getcwd(), "", wildcard, wx.ID_OPEN) if dialog.ShowModal() == wx.ID_OK: print(dialog.GetPath()) img = Image.open(dialog.GetPath()) imag = img.resize([64, 64]) image = np.array(imag) result = evaluate_one_image(image) result_text = wx.StaticText(self.pnl, label=result, pos=(320, 0)) font = result_text.GetFont() font.PointSize += 8 result_text.SetFont(font) self.initimage(name= dialog.GetPath()) # 生成图片控件
Example #3
Source File: sct_plugin.py From spinalcordtoolbox with MIT License | 6 votes |
def on_button_run(self, event): # Build and run SCT command fname_im = self.hbox_im.textctrl.GetValue() fname_seg = self.hbox_seg.textctrl.GetValue() contrast = self.rbox_contrast.GetStringSelection() base_name = os.path.basename(fname_seg) fname, fext = base_name.split(os.extsep, 1) fname_out = "{}_labeled.{}".format(fname, fext) cmd_line = "sct_label_vertebrae -i {} -s {} -c {}".format(fname_im, fname_seg, contrast) self.call_sct_command(cmd_line) # Add output to the list of overlay image = Image(fname_out) # <class 'fsl.data.image.Image'> overlayList.append(image) opts = displayCtx.getOpts(image) opts.cmap = 'subcortical'
Example #4
Source File: sct_plugin.py From spinalcordtoolbox with MIT License | 6 votes |
def on_button_run(self, event): # Build and run SCT command fname_input = self.hbox_filein.textctrl.GetValue() contrast = self.rbox_contrast.GetStringSelection() base_name = os.path.basename(fname_input) fname, fext = base_name.split(os.extsep, 1) fname_out = "{}_seg.{}".format(fname, fext) cmd_line = "sct_deepseg_sc -i {} -c {}".format(fname_input, contrast) self.call_sct_command(cmd_line) # Add output to the list of overlay image = Image(fname_out) # <class 'fsl.data.image.Image'> overlayList.append(image) opts = displayCtx.getOpts(image) opts.cmap = 'red'
Example #5
Source File: sct_plugin.py From spinalcordtoolbox with MIT License | 6 votes |
def on_button_run(self, event): # Build and run SCT command fname_input = self.hbox_filein.textctrl.GetValue() contrast = self.rbox_contrast.GetStringSelection() base_name = os.path.basename(fname_input) fname, fext = base_name.split(os.extsep, 1) fname_out = "{}_seg.{}".format(fname, fext) cmd_line = "sct_propseg -i {} -c {}".format(fname_input, contrast) self.call_sct_command(cmd_line) # Add output to the list of overlay image = Image(fname_out) # <class 'fsl.data.image.Image'> overlayList.append(image) opts = displayCtx.getOpts(image) opts.cmap = 'red'
Example #6
Source File: gui.py From four_flower with MIT License | 6 votes |
def OnSelect(self, event): wildcard = "image source(*.jpg)|*.jpg|" \ "Compile Python(*.pyc)|*.pyc|" \ "All file(*.*)|*.*" dialog = wx.FileDialog(None, "Choose a file", os.getcwd(), "", wildcard, wx.ID_OPEN) if dialog.ShowModal() == wx.ID_OK: print(dialog.GetPath()) img = Image.open(dialog.GetPath()) imag = img.resize([64, 64]) image = np.array(imag) result = evaluate_one_image(image) result_text = wx.StaticText(self.pnl, label=result, pos=(320, 0)) font = result_text.GetFont() font.PointSize += 8 result_text.SetFont(font) self.initimage(name= dialog.GetPath()) # 生成图片控件
Example #7
Source File: gui.py From superpaper with MIT License | 6 votes |
def resize_and_bitmap(self, fname, size, enhance_color=False): """Take filename of an image and resize and center crop it to size.""" try: pil = resize_to_fill(Image.open(fname), size, quality="fast") except UnidentifiedImageError: msg = ("Opening image '%s' failed with PIL.UnidentifiedImageError." "It could be corrupted or is of foreign type.") % fname sp_logging.G_LOGGER.info(msg) # show_message_dialog(msg) black_bmp = wx.Bitmap.FromRGBA(size[0], size[1], red=0, green=0, blue=0, alpha=255) if enhance_color: return (black_bmp, black_bmp) return black_bmp img = wx.Image(pil.size[0], pil.size[1]) img.SetData(pil.convert("RGB").tobytes()) if enhance_color: converter = ImageEnhance.Color(pil) pilenh_bw = converter.enhance(0.25) brightns = ImageEnhance.Brightness(pilenh_bw) pilenh = brightns.enhance(0.45) imgenh = wx.Image(pil.size[0], pil.size[1]) imgenh.SetData(pilenh.convert("RGB").tobytes()) return (img.ConvertToBitmap(), imgenh.ConvertToBitmap()) return img.ConvertToBitmap()
Example #8
Source File: make_timelapse.py From Pigrow with GNU General Public License v3.0 | 6 votes |
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
Example #9
Source File: gui.py From superpaper with MIT License | 6 votes |
def create_thumb_bmp(self, filename): wximg = wx.Image(filename, type=wx.BITMAP_TYPE_ANY) imgsize = wximg.GetSize() w2h_ratio = imgsize[0]/imgsize[1] if w2h_ratio > 1: target_w = self.tsize[0] target_h = target_w/w2h_ratio pos = (0, round((target_w - target_h)/2)) else: target_h = self.tsize[1] target_w = target_h*w2h_ratio pos = (round((target_h - target_w)/2), 0) bmp = wximg.Scale( target_w, target_h, quality=wx.IMAGE_QUALITY_BOX_AVERAGE ).Resize( self.tsize, pos ).ConvertToBitmap() return bmp
Example #10
Source File: configuration_dialogs.py From superpaper with MIT License | 6 votes |
def onChooseTestImage(self, event): """Open a file dialog to choose a test image.""" with wx.FileDialog(self, "Choose a test image", wildcard=("Image files (*.jpg;*.jpeg;*.png;*.bmp;*.gif;*.tiff;*.webp)" "|*.jpg;*.jpeg;*.png;*.bmp;*.gif;*.tiff;*.webp"), defaultDir=self.frame.defdir, style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST) as file_dialog: if file_dialog.ShowModal() == wx.ID_CANCEL: return # the user changed their mind # Proceed loading the file chosen by the user self.test_image = file_dialog.GetPath() self.tc_testimage.SetValue( os.path.basename(self.test_image) ) return
Example #11
Source File: sct_plugin.py From spinalcordtoolbox with MIT License | 5 votes |
def on_button_run(self, event): # Build and run SCT command fname_input = self.hbox_filein.textctrl.GetValue() base_name = os.path.basename(fname_input) fname, fext = base_name.split(os.extsep, 1) fname_out = "{}_gmseg.{}".format(fname, fext) cmd_line = "sct_deepseg_gm -i {} -o {}".format(fname_input, fname_out) self.call_sct_command(cmd_line) # Add output to the list of overlay image = Image(fname_out) # <class 'fsl.data.image.Image'> overlayList.append(image) opts = displayCtx.getOpts(image) opts.cmap = 'yellow'
Example #12
Source File: Icons.py From EventGhost with GNU General Public License v2.0 | 5 votes |
def _GetPil(self): """ Return a PIL image of the icon. """ stream = StringIO(b64decode(self.key)) pil = Image.open(stream).convert("RGBA") stream.close() return pil
Example #13
Source File: Icons.py From EventGhost with GNU General Public License v2.0 | 5 votes |
def _GetPil(self): """ Return a PIL image of the icon. """ small = self.key.pil.resize((12, 12), Image.BICUBIC) image = PLUGIN_PIL.copy() image.paste(small, (4, 4), small) return image
Example #14
Source File: Icons.py From EventGhost with GNU General Public License v2.0 | 5 votes |
def _GetPil(self): """ Return a PIL image of the icon. """ return Image.open(self.key).convert("RGBA")
Example #15
Source File: __init__.py From EventGhost with GNU General Public License v2.0 | 5 votes |
def piltoimage(pil, hasAlpha): """ Convert PIL Image to wx.Image. """ image = wx.EmptyImage(*pil.size) rgbPil = pil.convert('RGB') if hasAlpha: image.SetData(rgbPil.tobytes()) image.SetAlphaData(pil.convert("RGBA").tobytes()[3::4]) else: new_image = rgbPil data = new_image.tobytes() image.SetData(data) return image
Example #16
Source File: main.py From python-examples with MIT License | 5 votes |
def InitUI(self): img_color = wx.Image('Obrazy/furas.png') img_grey = img_color.ConvertToGreyscale(0.3, 0.3, 0.3) self.hbox = wx.BoxSizer(wx.HORIZONTAL) self.panel = wx.Panel(self) self.panel.SetSizer(self.hbox) self.bitmap_color = wx.Bitmap(img_color) self.bitmap_grey = wx.Bitmap(img_grey) #self.image = wx.StaticBitmap(self.panel, 1, self.bitmap_color) self.image = wx.BitmapButton(self.panel, 1, self.bitmap_color, style=wx.BORDER_NONE) # use 0 to not resize image to full window self.hbox.Add(self.image, 0) # binds don't work on Linux for StaticBitmap # but they works for BitmapButton (but Button has border) self.image.Bind(wx.EVT_ENTER_WINDOW, self.OnOver) self.image.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeave) # set color to see how many space use it self.panel.SetBackgroundColour((0,255,0)) # set color to see how many space use it self.image.SetBackgroundColour((255,0,0))
Example #17
Source File: main_frame.py From Rule-based_Expert_System with GNU General Public License v2.0 | 5 votes |
def show_picture(self, path, pos): pic = wx.Image(path, wx.BITMAP_TYPE_PNG).ConvertToBitmap() bmp = wx.StaticBitmap(self, 0, pic, pos=pos) bmp.Show()
Example #18
Source File: backend_wxagg.py From coffeegrindsize with MIT License | 5 votes |
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.Image(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))
Example #19
Source File: Beremiz.py From OpenPLC_Editor with GNU General Public License v3.0 | 5 votes |
def ShowSplashScreen(self): class Splash(AdvancedSplash): Painted = False def OnPaint(_self, event): # pylint: disable=no-self-argument AdvancedSplash.OnPaint(_self, event) if not _self.Painted: # trigger app start only once _self.Painted = True wx.CallAfter(self.AppStart) bmp = wx.Image(self.splashPath).ConvertToBitmap() self.splash = Splash(None, bitmap=bmp, agwStyle=AS_NOTIMEOUT | AS_CENTER_ON_SCREEN)
Example #20
Source File: main_frame.py From Rule-based_Expert_System with GNU General Public License v2.0 | 5 votes |
def __init__(self, parent, id, title, size): wx.Frame.__init__(self, parent, id, title, style=wx.DEFAULT_FRAME_STYLE ^ (wx.RESIZE_BORDER | wx.MINIMIZE_BOX | wx.MAXIMIZE_BOX)) self.SetSize(size) self.Center() self.sourceLabel = wx.StaticText(self, label='Source Image', pos=(150, 10), size=(40, 25)) self.detectionLabel = wx.StaticText(self, label='Detection Image', pos=(550, 10), size=(40, 25)) self.openPicButton = wx.Button(self, label='Open Image', pos=(830, 30), size=(150, 30)) self.openPicButton.Bind(wx.EVT_BUTTON, self.open_picture) self.openEditorButton = wx.Button(self, label='Open Rule Editor', pos=(830, 70), size=(150, 30)) self.openEditorButton.Bind(wx.EVT_BUTTON, self.open_rule_editor) self.showRuleButton = wx.Button(self, label='Show Rules', pos=(830, 110), size=(150, 30)) self.showRuleButton.Bind(wx.EVT_BUTTON, self.show_rules) self.showFactButton = wx.Button(self, label='Show Facts', pos=(830, 150), size=(150, 30)) self.showFactButton.Bind(wx.EVT_BUTTON, self.show_facts) self.treeLabel = wx.StaticText(self, label='What shape do you want', pos=(830, 200), size=(40, 25)) self.shapeTree = wx.TreeCtrl(self, pos=(830, 220), size=(160, 210)) root = self.shapeTree.AddRoot('All Shapes') self.add_tree_nodes(root, shape_items.tree) self.shapeTree.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.shape_chosen) self.shapeTree.Expand(root) self.show_picture('init_source.png', (10, 30)) self.show_picture('init_detection.png', (420, 30)) self.resultLabel = wx.StaticText(self, label='Detection Result', pos=(100, 450), size=(40, 25)) self.resultText = wx.TextCtrl(self, pos=(10, 480), size=(310, 280), style=wx.TE_MULTILINE | wx.TE_READONLY) self.matchedFactLabel = wx.StaticText(self, label='Matched Facts', pos=(430, 450), size=(40, 25)) self.matchedFactText = wx.TextCtrl(self, pos=(340, 480), size=(310, 280), style=wx.TE_MULTILINE | wx.TE_READONLY) self.hitRuleLabel = wx.StaticText(self, label='Hit Rules', pos=(780, 450), size=(40, 25)) self.hitRuleText = wx.TextCtrl(self, pos=(670, 480), size=(310, 280), style=wx.TE_MULTILINE | wx.TE_READONLY) self.title = title self.pic_path = None self.engine = None self.contour_num = None self.Show()
Example #21
Source File: Icons.py From EventGhost with GNU General Public License v2.0 | 5 votes |
def GetBitmap(filePath): """ Returns a wx.Bitmap loaded from 'filePath'. Uses PIL functions, because this way we have better alpha channel handling. """ return PilToBitmap(Image.open(filePath).convert("RGBA"))
Example #22
Source File: Icons.py From EventGhost with GNU General Public License v2.0 | 5 votes |
def GetInternalImage(name): return wx.Image(join(eg.imagesDir, name + ".png"), wx.BITMAP_TYPE_PNG)
Example #23
Source File: __init__.py From EventGhost with GNU General Public License v2.0 | 5 votes |
def __call__(self): SendMessage(GetForegroundWindow(), WM_SYSCOMMAND, SC_SCREENSAVE, 0) #----------------------------------------------------------------------------- # Image actions #-----------------------------------------------------------------------------
Example #24
Source File: __init__.py From EventGhost with GNU General Public License v2.0 | 5 votes |
def __call__(self, imageFileName='', style=1): if imageFileName: image = wx.Image(imageFileName) imageFileName = os.path.join( eg.folderPath.RoamingAppData, "Microsoft", "Wallpaper1.bmp" ) image.SaveFile(imageFileName, wx.BITMAP_TYPE_BMP) tile, wstyle = (("0", "0"), ("1", "0"), ("0", "2"))[style] hKey = _winreg.CreateKey( _winreg.HKEY_CURRENT_USER, "Control Panel\\Desktop" ) _winreg.SetValueEx( hKey, "TileWallpaper", 0, _winreg.REG_SZ, tile ) _winreg.SetValueEx( hKey, "WallpaperStyle", 0, _winreg.REG_SZ, wstyle ) _winreg.CloseKey(hKey) res = SystemParametersInfo( SPI_SETDESKWALLPAPER, 0, create_unicode_buffer(imageFileName), SPIF_SENDCHANGE | SPIF_UPDATEINIFILE ) if res == 0: self.PrintError(ctypes.FormatError())
Example #25
Source File: Icons.py From EventGhost with GNU General Public License v2.0 | 5 votes |
def _GetPil(self): """ Return a PIL image of the icon. """ small = self.key.pil.resize((12, 12), Image.BICUBIC) image = ACTION_PIL.copy() image.paste(small, (4, 4), small) return image
Example #26
Source File: local_display.py From Pigrow with GNU General Public License v3.0 | 5 votes |
def display_image(self, path_to_image): #img_bmp = wx.StaticBitmap(self, -1, wx.Image(path_to_image, wx.BITMAP_TYPE_ANY).ConvertToBitmap()), 0, wx.ALL, 2) bitmap = wx.Bitmap(1, 1) bitmap.LoadFile(path_to_image, wx.BITMAP_TYPE_ANY) self.img_bmp_box.SetBitmap(bitmap) MainApp.window_self.Layout()
Example #27
Source File: gui.py From four_flower with MIT License | 5 votes |
def initimage(self, name): imageShow = wx.Image(name, wx.BITMAP_TYPE_ANY) sb = wx.StaticBitmap(self.pnl, -1, imageShow.ConvertToBitmap(), pos=(0,30), size=(600,400)) return sb
Example #28
Source File: __init__.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
def get(self, key, size=None, base=None, ext='.png'): if self._data.has_key((key, size)): return self._data[(key, size)] name = self.resolve_filename(key, size, base, ext) i = wx.Image(name, wx.BITMAP_TYPE_PNG) if not i.Ok(): raise Exception("The image is not valid: %r" % name) self._data[(key, size)] = i return i
Example #29
Source File: about.py From nuxhash with GNU General Public License v3.0 | 5 votes |
def __init__(self, parent, *args, **kwargs): wx.Panel.__init__(self, parent, *args, **kwargs) h_sizer = wx.BoxSizer(orient=wx.HORIZONTAL) self.SetSizer(h_sizer) v_sizer = wx.BoxSizer(orient=wx.VERTICAL) h_sizer.Add(v_sizer, wx.SizerFlags().Proportion(1.0) .Align(wx.ALIGN_CENTER)) with open(LOGO_PATH, 'rb') as f: logo = wx.Image(f, type=wx.BITMAP_TYPE_PNG) v_sizer.Add(wx.StaticBitmap(self, bitmap=wx.Bitmap(logo)), wx.SizerFlags().Align(wx.ALIGN_CENTER)) v_sizer.AddSpacer(15) appName = wx.StaticText( self, label=f'nuxhash {__version__}', style=wx.ALIGN_CENTER) appName.SetFont(self.GetFont().Scale(2.0)) v_sizer.Add(appName, wx.SizerFlags().Expand()) v_sizer.AddSpacer(15) v_sizer.Add(wx.StaticText(self, label='A NiceHash client for Linux.', style=wx.ALIGN_CENTER), wx.SizerFlags().Expand()) v_sizer.AddSpacer(15) copyright = wx.StaticText(self, label=__copyright__, style=wx.ALIGN_CENTER) copyright.SetFont(self.GetFont().Scale(0.8)) v_sizer.Add(copyright, wx.SizerFlags().Expand()) v_sizer.AddSpacer(30) links = wx.BoxSizer(orient=wx.HORIZONTAL) links.Add(HyperLinkCtrl(self, label='Website', URL=WEBSITE)) links.AddSpacer(30) links.Add(HyperLinkCtrl(self, label='License', URL=LICENSE)) v_sizer.Add(links, wx.SizerFlags().Align(wx.ALIGN_CENTER))
Example #30
Source File: wxwrap.py From grass-tangible-landscape with GNU General Public License v2.0 | 5 votes |
def ImageFromStream(stream, type=wx.BITMAP_TYPE_ANY, index=-1): if wxPythonPhoenix: return wx.Image(stream=stream, type=type, index=index) else: return wx.ImageFromStream(stream=stream, type=type, index=index)