# -*- coding: utf-8 -*-
from PIL import Image
import wx
'''PIL Image'''
pilImage = Image.open('1.png')
'''wx.Image'''
wxImg = PilImg2WxImg(pilImage)
'''wx.Bitmap'''
bitmap = wx.BitmapFromImage(wxImg)
'''wx.StaticBitmap'''
staticBitmap = wx.StaticBitmap(parent, -1, imgObj)
def PilImg2WxImg(pilImg):
'''PIL的image转化为wxImage'''
image = wx.EmptyImage(pilImg.size[0],pilImg.size[1])
image.SetData(pilImg.convert("RGB").tostring())
image.SetAlphaData(pilImg.convert("RGBA").tostring()[3::4])
return image
def WxImg2PilImg(wxImg):
'''wxImage转化为PIL的image'''
pilImage = Image.new('RGB', (wxImg.GetWidth(), wxImg.GetHeight()))
pilImage.fromstring(wxImg.GetData())
if wxImg.HasAlpha():
pilImage.convert( 'RGBA' )
wxAlphaStr = wxImg.GetAlphaData()
pilAlphaImage = Image.fromstring( 'L', (wxImg.GetWidth(), wxImg.GetHeight()), wxAlphaStr )
pilImage.putalpha( pilAlphaImage )
return pilImage