Python wx 模块,BitmapFromImage() 实例源码

我们从Python开源项目中,提取了以下25个代码示例,用于说明如何使用wx.BitmapFromImage()

项目:augment3D    作者:yulkang    | 项目源码 | 文件源码
def show_file(self, imageFile, fullPath):
        """ Load the DICOM file, make sure it contains at least one
        image, and set it up for display by OnPaint().  ** be
        careful not to pass a unicode string to read_file or it will
        give you 'fp object does not have a defer_size attribute,
        or some such."""
        ds = pydicom.read_file(str(fullPath))
        ds.decode()                                         # change strings to unicode
        self.populateTree(ds)
        if 'PixelData' in ds:
            self.dImage = self.loadPIL_LUT(ds)
            if self.dImage is not None:
                tmpImage = self.ConvertPILToWX(self.dImage, False)
                self.bitmap = wx.BitmapFromImage(tmpImage)
                self.Refresh()

# ------ This is just the initialization of the App  -------------------------


# =======================================================
# The main App Class.
# =======================================================
项目:bonsu    作者:bonsudev    | 项目源码 | 文件源码
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()
项目:Pigrow    作者:Pragmatismo    | 项目源码 | 文件源码
def updateUI(self, capsdir):
        print("---UPDATING USER INTERFACE ---")
        capsdir = self.capsfolder_box.GetValue()
        fframe = self.firstframe_box.GetValue()
        lframe = self.lastframe_box.GetValue()
        if fframe == '':
            fframe = 0
        if lframe == '':
            lframe = len(cap_files) - 1
        last_pic  = str(capsdir + cap_files[lframe])
        first_pic = str(capsdir + cap_files[fframe])
        self.firstframe_box.SetValue(str(fframe))
        self.lastframe_box.SetValue(str(lframe))
        self.updatelastpic(lframe)
        self.updatefirstpic(fframe)
     #Cap graph
        cap_size_graph = self.graph_caps(cap_files, graphdir)
        scale_size_graph = first_pic = self.scale_pic(cap_size_graph, 300)
        self.cap_thumb.SetBitmap(wx.BitmapFromImage(scale_size_graph))
项目:pinder    作者:dhharris    | 项目源码 | 文件源码
def view(self, file):
        '''
        Called when loading a new image. Pass arg bytesIO image file
        '''
        img = wx.Image(file, wx.BITMAP_TYPE_ANY)
        # scale the image, preserving the aspect ratio
        W = img.GetWidth()
        H = img.GetHeight()
        if W > H:
            NewW = self.PhotoMaxSize
            NewH = self.PhotoMaxSize * H / W
        else:
            NewH = self.PhotoMaxSize
            NewW = self.PhotoMaxSize * W / H
        img = img.Scale(NewW, NewH)

        self.imageCtrl.SetBitmap(wx.BitmapFromImage(img))
        self.panel.Refresh()
项目:bids    作者:robertoostenveld    | 项目源码 | 文件源码
def show_file(self, imageFile, fullPath):
        """ Load the DICOM file, make sure it contains at least one
        image, and set it up for display by OnPaint().  ** be
        careful not to pass a unicode string to read_file or it will
        give you 'fp object does not have a defer_size attribute,
        or some such."""
        ds = pydicom.read_file(str(fullPath))
        ds.decode()                                         # change strings to unicode
        self.populateTree(ds)
        if 'PixelData' in ds:
            self.dImage = self.loadPIL_LUT(ds)
            if self.dImage is not None:
                tmpImage = self.ConvertPILToWX(self.dImage, False)
                self.bitmap = wx.BitmapFromImage(tmpImage)
                self.Refresh()

# ------ This is just the initialization of the App  -------------------------


# =======================================================
# The main App Class.
# =======================================================
项目:wxpythoncookbookcode    作者:driscollis    | 项目源码 | 文件源码
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)
项目:wxpythoncookbookcode    作者:driscollis    | 项目源码 | 文件源码
def loadImage(self, image):
        """
        Load the image into the application for display
        """
        image_name = os.path.basename(image)
        img = wx.Image(image, wx.BITMAP_TYPE_ANY)
        # scale the image, preserving the aspect ratio
        W = img.GetWidth()
        H = img.GetHeight()
        if W > H:
            NewW = self.photoMaxSize
            NewH = self.photoMaxSize * H / W
        else:
            NewH = self.photoMaxSize
            NewW = self.photoMaxSize * W / H
        img = img.Scale(NewW,NewH)

        self.imageCtrl.SetBitmap(wx.BitmapFromImage(img))
        self.imageLabel.SetLabel(image_name)
        self.Refresh()
        Publisher().sendMessage("resize", "")
项目:code    作者:ActiveState    | 项目源码 | 文件源码
def convert(self):
        self.Bind(wx.EVT_TIMER, self.OnTimer2, self.timer2)
        self.dltext.SetLabel(self.query)
        self.panel.Layout()
        imageFile = 'Files\image.jpg'

        data = open(imageFile, "rb").read()
        # convert to a data stream
        stream = cStringIO.StringIO(data)
        # convert to a bitmap
        bmp = wx.BitmapFromImage( wx.ImageFromStream( stream ))
        # show the bitmap, (5, 5) are upper left corner coordinates
        thumb = wx.StaticBitmap(self, -1, bmp, (90,255))

        self.Hide()
        self.Show()

        self.text.SetLabel('Converting...')
        if self.rb1.GetValue() == True:
            self.timer2.Start(1000)
            worker1 = threading.Thread(target=lambda: self.getfile.get_file('http://www.youtube.com/%s'%self.vidurl, '320'))
            worker1.start()

        elif self.rb2.GetValue() == True:
            self.timer2.Start(600)
            worker1 = threading.Thread(target=lambda: self.getfile.get_file('http://www.youtube.com/%s'%self.vidurl, '128'))
            worker1.start()
项目:stopgo    作者:notklaatu    | 项目源码 | 文件源码
def BuildTimeline(self,dbfile):

        for child in self.panel3.GetChildren():
            logging.exception(child)
            child.Destroy()

        # the last frame is
        latestfram = self.cur.execute("SELECT * FROM Timeline ORDER BY Image DESC LIMIT 1")
        #latestfram = self.cur.execute("SELECT * FROM Timeline WHERE ID = (SELECT MAX(ID) FROM TABLE) AND Blackspot = 0");
        try:
            for entry in latestfram:
                self.framlog = int(entry[1].split('.')[0])
                self.framlog += 1
                logging.exception(self.framlog)
        except:
            logging.exception('Looking for last frame but did not find.')
            pass

        # timeline contains
        tbl_timeline = self.cur.execute("SELECT * FROM Timeline WHERE Blackspot=0")

        for entry in tbl_timeline:
            img = self.MakeThumbnail(os.path.join(self.imgdir, entry[1]), self.thumbsize)
            self.imageCtrl = wx.StaticBitmap(self.panel3, wx.ID_ANY, 
                                             wx.BitmapFromImage(img),name=entry[1]) 
            self.imageCtrl.SetBitmap(wx.BitmapFromImage(img))
            self.imageCtrl.Bind( wx.EVT_LEFT_DOWN, self.OnLeftClick )
            self.imageCtrl.Bind( wx.EVT_LEFT_UP, self.OnLeftRelease )

            logging.exception(self.imageCtrl.GetId() )
            self.hbox2.Add( self.imageCtrl, 0, wx.ALL, 5 )

        self.Layout()
        self.panel3.SetFocus()
        self.BindKeys(dbfile)

        self.hbox2.Layout()
        self.panel3.Refresh()
        self.panel3.Update()

        self.Refresh()
项目:stopgo    作者:notklaatu    | 项目源码 | 文件源码
def MakeThumbnail(self, filepath, PhotoMaxSize):
        img = wx.Image(filepath, wx.BITMAP_TYPE_ANY)
        # scale image, preserve aspect ratio
        W = img.GetWidth()
        H = img.GetHeight()
        if W > H:
            NewW = PhotoMaxSize
            NewH = PhotoMaxSize * H / W
        else:
            NewH = PhotoMaxSize
            NewW = PhotoMaxSize * W / H
        img = img.Scale(NewW,NewH)
        imgb = wx.BitmapFromImage(img)
        return img
项目:stopgo    作者:notklaatu    | 项目源码 | 文件源码
def OnLeftClick(self,e):

        if self.hasSelected:
            # if selection exists, take badge from previous
            img = self.MakeThumbnail(os.path.join(self.imgdir, self.selected.GetName() ), self.thumbsize)
            self.selected.SetBitmap(wx.BitmapFromImage(img) )
            if e.GetId() == self.previous:
                self.hasSelected  = True
            else:
                self.hasSelected  = False
项目:stopgo    作者:notklaatu    | 项目源码 | 文件源码
def OnLeftRelease(self,e):

        self.player.stop()
        self.brec.SetBitmapLabel(self.brecxicon)
        self.bplay.SetBitmapLabel(self.bplayicon)

        if self.hasSelected:
            #the frame selected was clicked
            img = self.MakeThumbnail(os.path.join(self.imgdir, self.selected.GetName() ), self.thumbsize)
            self.selected.SetBitmap(wx.BitmapFromImage(img) )
            self.hasSelected = True
            self.previous = 0
            self.player.play()
            self.viewport.Refresh()
            self.brec.SetBitmapLabel(self.brecicon)

        if not self.hasSelected:
            # we clicked something new
            # get new selection
            self.selected = e.GetEventObject()
            # highlight new selection
            img = self.MakeThumbnail(os.path.join(self.imgdir, self.selected.GetName() ), self.thumbsize + 3)
            imgb = wx.BitmapFromImage(img)
            dc = wx.MemoryDC(imgb)
            staricon = wx.Image(os.path.join(os.path.dirname(__file__),'..','..','stopgo','images','select.png') )
            star = wx.BitmapFromImage(staricon)
            dc.DrawBitmap(star,133,0)
            dc.SelectObject(wx.NullBitmap)
            del dc
            control = wx.StaticBitmap(self, -1, imgb)
            self.selected.SetBitmap(imgb)
            self.hasSelected = True
            self.previous = self.selected.GetId()

            #paint canvas
            img = self.MakeThumbnail(os.path.join( self.imgdir, self.selected.GetName() ), self.screenHeight*.9)
            self.GetStatusBar().SetStatusText(self.selected.GetName(), 0)
            self.PaintCanvas(img)

            self.viewport.Refresh()
项目:stopgo    作者:notklaatu    | 项目源码 | 文件源码
def PaintCanvas(self,img):
        bmp    = wx.BitmapFromImage( img )
        canvas = wx.StaticBitmap( self.viewport, bitmap=bmp, pos=(0,0) )
项目:stopgo    作者:notklaatu    | 项目源码 | 文件源码
def TakeSnapshot(self,e,args):

        logging.exception('CAPTURE')
        if self.camset == 1:
            self.framlog += 1

            #print(self.camhero)#DEBUG
            vidcap = vlc.libvlc_video_take_snapshot(self.player,0,os.path.join(self.imgdir, str(self.framlog).zfill(3)+'.png'),0,0)
            self.cur.execute('INSERT INTO Timeline VALUES(Null,?,?)', (str(self.framlog).zfill(3)+'.png',0))
            # add graphically to timeline
            img = self.MakeThumbnail(os.path.join(self.imgdir, str(self.framlog).zfill(3)+'.png'), self.thumbsize)
            self.imageCtrl = wx.StaticBitmap(self.panel3, wx.ID_ANY, wx.BitmapFromImage(img),name=str(self.framlog).zfill(3)+'.png') 
            self.imageCtrl.SetBitmap(wx.BitmapFromImage(img))
            self.imageCtrl.Bind( wx.EVT_LEFT_DOWN, self.OnLeftClick )
            self.imageCtrl.Bind( wx.EVT_LEFT_UP, self.OnLeftRelease )
            logging.exception(self.imageCtrl.GetId() )
            self.hbox2.Add( self.imageCtrl, 0, wx.ALL, 5 )

            # scroll right 100% to get close to new frame
            self.panel3.Scroll(self.thumbsize,0)
            self.Layout()
            # draw new frame
            self.hbox2.Layout()
            self.panel3.Refresh()
            # scroll WAY right again to show frame
            self.panel3.Scroll(200,0)
            # send the shot to onion skin
            img = os.path.join(self.imgdir, str(self.framlog).zfill(3)+'.png')
            self.OnionSkin(img)
            logging.exception(self.framlog)

        else:
            dlg = wx.MessageDialog(self, 'Please select your camera first.','',wx.OK | wx.ICON_ERROR)
            val = dlg.ShowModal()
            if val == wx.ID_OK:
                dlg.Destroy()
            if val == wx.ID_CANCEL:
                dlg.Destroy()

        self.player.play()
        self.brec.SetBitmapLabel(self.brecicon)
项目:Pigrow    作者:Pragmatismo    | 项目源码 | 文件源码
def updatelastpic(self, lframe):
        capsdir = self.capsfolder_box.GetValue()
        last_pic = str(capsdir + cap_files[lframe])
        if os.path.exists(last_pic):
            last_pic = wx.Image(last_pic, wx.BITMAP_TYPE_ANY)
            last_pic = self.scale_pic(last_pic, 500)
            self.last_pic.SetBitmap(wx.BitmapFromImage(last_pic))
            lpicdate = self.date_from_fn(cap_files[lframe])
            self.lpic_text.SetLabel('Frame ' + str(lframe) + '  -  ' + str(lpicdate))
        else:
            self.last_pic.SetBitmap(wx.EmptyBitmap(10,10))
            self.fpic_text.SetLabel('end')
项目:Pigrow    作者:Pragmatismo    | 项目源码 | 文件源码
def updatefirstpic(self, fframe):
        capsdir = self.capsfolder_box.GetValue()
        first_pic = str(capsdir + cap_files[fframe])
        if os.path.exists(first_pic):
            first_pic = wx.Image(first_pic, wx.BITMAP_TYPE_ANY)
            first_pic = self.scale_pic(first_pic, 500)
            fpicdate = self.date_from_fn(cap_files[fframe])
            self.fpic_text.SetLabel('Frame ' + str(fframe) + '  -  ' + str(fpicdate))
            self.first_pic.SetBitmap(wx.BitmapFromImage(first_pic))
        else:
            self.first_pic.SetBitmap(wx.EmptyBitmap(10,10))
            self.fpic_text.SetLabel('start')
项目:Pigrow    作者:Pragmatismo    | 项目源码 | 文件源码
def capture_cam_image(self, e):
        target_ip = self.tb_ip.GetValue()
        target_user = self.tb_user.GetValue()
        target_pass = self.tb_pass.GetValue()
        cam_capture_choice = self.cam_combo.GetValue()
        s_val = str(self.tb_s.GetValue())
        c_val = str(self.tb_c.GetValue())
        g_val = str(self.tb_g.GetValue())
        b_val = str(self.tb_b.GetValue())
        x_dim = str(self.tb_x.GetValue())
        y_dim = str(self.tb_y.GetValue())
        cam_select = self.cam_select_cb.GetValue()
        if cam_capture_choice == 'fswebcam':
            ctrl_text_string = self.setting_string_tb.GetValue()
            ctrl_test_value = self.setting_value_tb.GetValue()
            cmd_str = self.cmds_string_tb.GetValue()
            if not ctrl_test_value == '':
                found_login, cam_output, output_file = take_test_image(target_ip, target_user, target_pass,
                                                                       s_val, c_val, g_val, b_val,
                                                                       x_dim, y_dim, cam_select,
                                                                       cam_capture_choice,
                                                                       ctrl_test_value=ctrl_test_value, ctrl_text_string=ctrl_text_string, cmd_str=cmd_str)
            else:
                found_login, cam_output, output_file = take_test_image(target_ip, target_user, target_pass,
                                                                       s_val, c_val, g_val, b_val,
                                                                       x_dim, y_dim, cam_select,
                                                                       cam_capture_choice, cmd_str=cmd_str)
        else:
            found_login, cam_output, output_file = take_test_image(target_ip, target_user, target_pass,
                                                                   s_val, c_val, g_val, b_val,
                                                                   x_dim, y_dim, cam_select,
                                                                   cam_capture_choice)
        photo_location = get_test_pic(target_ip, target_user, target_pass, output_file)
        self.main_image.SetBitmap(wx.BitmapFromImage(wx.Image(photo_location, wx.BITMAP_TYPE_ANY)))
项目:Pigrow    作者:Pragmatismo    | 项目源码 | 文件源码
def capture_unset_cam_image(self, e):
        target_ip = self.tb_ip.GetValue()
        target_user = self.tb_user.GetValue()
        target_pass = self.tb_pass.GetValue()
        x_dim = self.tb_x.GetValue()
        y_dim = self.tb_y.GetValue()
        cam_select = self.cam_select_cb.GetValue()
        extra_args = '' #will be used for camera select
        cam_capture_choice = self.cam_combo.GetValue()
        found_login, cam_output, output_file = take_unset_test_image(target_ip, target_user, target_pass, x_dim, y_dim, cam_select, cam_capture_choice)
        #print cam_output
        photo_location = get_test_pic(target_ip, target_user, target_pass, output_file)
        #print photo_location
        self.main_image.SetBitmap(wx.BitmapFromImage(wx.Image(photo_location, wx.BITMAP_TYPE_ANY)))
项目:bonsu    作者:bonsudev    | 项目源码 | 文件源码
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()
项目:bonsu    作者:bonsudev    | 项目源码 | 文件源码
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()
项目:bonsu    作者:bonsudev    | 项目源码 | 文件源码
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)
项目:MechWarfareScoring    作者:artanz    | 项目源码 | 文件源码
def OnPaint( self, event ):

        dc = wx.BufferedPaintDC( self )

        # Draw the camera image
        if self.Camera.Connected:
            try:
                stream = self.Camera.Update()
                if stream != None:
                    img = wx.ImageFromStream( stream )
                    bmp = wx.BitmapFromImage( img )
                    dc.DrawBitmap( bmp, 0, 0, True )
            except:
                pass

        # If camera not connected draw blank white screen
        else:
            dc.SetBrush( wx.WHITE_BRUSH )
            dc.DrawRectangle( -1, -1, CAMERA_SIZE_WIDTH, CAMERA_SIZE_HEIGHT )

        # Draw the SocketClient match data
        if self.SocketClient != None:
            dc.SetTextForeground( HUD_COLOR )

            # Clock
            min = self.SocketClient.MatchTime / 600
            sec = int((self.SocketClient.MatchTime -(min * 600)) * .1)

            dc.DrawText( str(min).rjust(2, "0") + ":" + str(sec).rjust(2, "0"), TIME_POSITION_X, TIME_POSITION_Y )

            # Scores
            for m in xrange(self.SocketClient.NumMechs):
                dc.DrawText( self.SocketClient.MechNames[m], SCORE_POSITION_X, SCORE_POSITION_Y1+(40*m) )
                dc.DrawText( str(self.SocketClient.MechHP[m]), SCORE_POSITION_X, SCORE_POSITION_Y2+(40*m) )

        # Draw the crosshairs
项目:bp5000    作者:isaiahr    | 项目源码 | 文件源码
def paint(self, ev):
        dc = wx.PaintDC(ev.GetEventObject())
        if self.dirty:
            dc.Clear()
            self.dirty = False
        w = min(self.GetSize()[0], self.img.GetWidth()-self.x)
        h = min(self.GetSize()[1], self.img.GetHeight()-self.y)
        bx, by = (0, 0)
        if self.img.GetWidth() > self.GetSize()[0]:
            if self.x + self.GetSize()[0] > self.img.GetWidth():
                self.x = self.img.GetWidth() - self.GetSize()[0]
            self.bx = 0
        else:
            bx = int(.5*(self.GetSize()[0] - self.img.GetWidth()))
            self.x = 0
            self.bx = bx
        if self.img.GetHeight() > self.GetSize()[1]:
            if self.y + self.GetSize()[1] > self.img.GetHeight():
                self.y = self.img.GetHeight() - self.GetSize()[1]
            self.by = 0
        else:
            by = int(.5*(self.GetSize()[1] - self.img.GetHeight()))
            self.y = 0
            self.by = by
        # update if within 100px of borders
        if self.GetParent().GetParent().GetParent().options.get("exprender"):
            if ((self.x < 100 and self.ax > 0) or (self.y < 100 and self.ay > 0)) or ((self.x + w > 1900) or (self.y + h > 1900)):
                self.updatebracketimg()
        sub = wx.Rect(self.x, self.y, w, h)
        bimg = wx.BitmapFromImage(self.img.GetSubImage(sub))
        dc.DrawBitmap(bimg, bx, by)
        if self.extimg:
            param0 = wx.BitmapFromImage(piltowx(self.extimg[0]))
            param1 = self.extimg[1]-self.x+self.bx
            param2 = self.extimg[2]-self.y+self.by
            dc.DrawBitmap(param0, param1, param2)
项目:bittray    作者:nkuttler    | 项目源码 | 文件源码
def get_icon(self, text):
        """
        Return a wx icon from a file like object containing the image
        with text.

        TODO: transparency support
        """
        background = self.conf.get_color('Look', 'background')
        foreground = self.conf.get_color('Look', 'color')
        font = ImageFont.truetype(
            self.conf.get_font_path(),
            self.conf.get_int('Look', 'size'),
        )
        if font is None:
            logger.critical("Font could not be looked up. Try setting "
                            "font_path in the configuration file to the full "
                            "path to a truetype font.")
        mask = Image.new('RGB', (WIDTH, HEIGHT), background)
        draw = ImageDraw.Draw(mask)
        draw.text(
            background,
            text,
            font=font,
            fill=foreground,
        )
        mask = self.trim(mask)
        buf = io.StringIO()
        mask.save(buf, 'png')
        buf.seek(0)
        icon = wx.IconFromBitmap(
            wx.BitmapFromImage(
                wx.ImageFromStream(
                    buf,
                    wx.BITMAP_TYPE_PNG
                )
            )
        )
        return icon
项目:bonsu    作者:bonsudev    | 项目源码 | 文件源码
def __init__(self, parent, info):
        wx.Dialog.__init__(self, parent, title="About Bonsu", size=(460,300))
        self.SetSizeHints(450,300,-1,-1)
        self.parent = parent
        self.info  = info
        self.vboxborder = wx.BoxSizer(wx.VERTICAL)
        self.vbox = wx.BoxSizer(wx.VERTICAL)
        self.icon = wx.Image(os.path.join(os.path.dirname(os.path.dirname(__file__)),'image',  'bonsu.ico'), wx.BITMAP_TYPE_ICO)
        if IsNotWX4():
            self.bitmap = wx.BitmapFromImage(self.icon)
        else:
            self.bitmap = wx.Bitmap(self.icon)
        self.staticbmp = wx.StaticBitmap(self, -1, self.bitmap)
        self.vbox.Add(self.staticbmp, 0, flag=wx.CENTER, border=5)
        namestr = info.GetName()+" "+info.GetVersion()
        self.namefont = wx.Font((parent.font.GetPointSize()+8),parent.font.GetFamily(),wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD)
        self.name = wx.StaticText(self, label=namestr)
        self.name.SetFont(self.namefont)
        self.vbox.Add((-1, 5))
        self.vbox.Add(self.name, 0, flag=wx.CENTER, border=5)
        self.vbox.Add((-1, 5))
        self.description = wx.StaticText(self, label=info.GetDescription(), style=wx.ALIGN_CENTRE_HORIZONTAL)
        self.description.Wrap(400)
        self.vbox.Add(self.description, 0, flag=wx.CENTER, border=5)
        self.vbox.Add((-1, 5))
        self.copyright = wx.StaticText(self, label=info.GetCopyright())
        self.vbox.Add(self.copyright, 0, flag=wx.CENTER, border=5)
        self.vbox.Add((-1, 5))
        if IsNotWX4():
            self.web = wx.StaticText(self, label=info.GetWebSite()[0])
        else:
            self.web = wx.StaticText(self, label=info.GetWebSiteURL())
        self.vbox.Add(self.web, 0, flag=wx.CENTER, border=5)
        self.vbox.Add((-1, 10))
        self.hbox = wx.BoxSizer(wx.HORIZONTAL)
        self.credits =wx.Button(self, label="More")
        self.Bind(wx.EVT_BUTTON, self.OnCredits, self.credits)
        self.hbox.Add(self.credits)
        self.hbox.Add((10, -1))
        self.license =wx.Button(self, label="License")
        self.Bind(wx.EVT_BUTTON, self.OnLicense, self.license)
        self.hbox.Add(self.license)
        self.hbox.Add((10, -1))
        self.close =wx.Button(self, label="Close")
        self.Bind(wx.EVT_BUTTON, self.OnClose, self.close)
        self.hbox.Add(self.close)
        self.vbox.Add(self.hbox, 0, flag=wx.CENTER, border=5)
        self.vbox.Add((-1, 10))
        self.vboxborder.Add(self.vbox, 1, flag=wx.CENTER|wx.LEFT|wx.RIGHT|wx.TOP|wx.BOTTOM, border=20)
        self.SetSizer( self.vboxborder )
        self.SetAutoLayout(True)
        self.Fit()
        self.Layout()
        self.Show()