PIL Image 转成 wx.Image、wx.Bitmap

import wx
from PIL import Image

def ConvertToWxImage():
    pilImage = Image.open('1.png')
    image = wx.EmptyImage(pilImage.size[0], pilImage.size[1])
    image.SetData(pilImage.convert("RGB").tostring())
    image.SetAlphaData(pilImage.convert("RGBA").tostring()[3::4])

    bitmap = wx.BitmapFromImage(image)
    return bitmap
class MyFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, title = "Test convert ")
        sizer = wx.BoxSizer(wx.HORIZONTAL)
        bitmap = ConvertToWxImage()
        bimCtr = wx.StaticBitmap(self, -1, bitmap)
        sizer.Add(bimCtr)
        self.SetSizerAndFit(sizer)

app = wx.PySimpleApp()
frm = MyFrame()
frm.Show()
app.MainLoop()
        

 

posted on 2013-07-29 09:18  |残阳|露  阅读(1481)  评论(0编辑  收藏  举报

导航