wx.StaticBitmap
我在其中时遇到问题SetBitmap
,它显示图像但总是复制图像:一个作为静态背景,一个作为我显示的位图。请看这个截图-> duplicate_image_wxstaticbitmap.png
这是我的代码:
import wx
import wx.xrc
from PIL import Image
class MyFrame1 ( wx.Frame ):
def __init__( self, parent ):
wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = wx.EmptyString, pos = wx.DefaultPosition, size = wx.Size( 440,514 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )
self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )
bSizer1 = wx.BoxSizer( wx.VERTICAL )
sbSizer1 = wx.StaticBoxSizer( wx.StaticBox( self, wx.ID_ANY, u"COMPOSITE" ), wx.VERTICAL )
self.composite_sb = wx.StaticBitmap( sbSizer1.GetStaticBox(), wx.ID_ANY, wx.NullBitmap, wx.DefaultPosition, wx.Size( 400,400 ), 0 )
sbSizer1.Add( self.composite_sb, 0, wx.ALL, 5 )
bSizer1.Add( sbSizer1, 1, wx.ALL|wx.EXPAND, 5 )
self.load_img_btn = wx.Button( self, wx.ID_ANY, u"Load Image", wx.DefaultPosition, wx.DefaultSize, 0 )
bSizer1.Add( self.load_img_btn, 0, wx.ALL|wx.EXPAND, 5 )
self.SetSizer( bSizer1 )
self.Layout()
self.Centre( wx.BOTH )
self.load_img_btn.Bind( wx.EVT_BUTTON, self.loadImage )
def loadImage( self, event ):
myPilImage = Image.open('result.tiff')
myWxImage = wx.EmptyImage( myPilImage.size[0], myPilImage.size[1] )
myWxImage.SetData( myPilImage.convert( 'RGB' ).tobytes() )
#myWxImage = myWxImage.Scale(400,400)
self.composite_sb.SetBitmap(wx.BitmapFromImage(myWxImage))
if __name__ == "__main__":
app = wx.App(False)
frame = MyFrame1(None)
frame.Show()
app.MainLoop()