PIL Image to wx.Image and wx.Bitmap

by @jehiah on 2007-10-02 14:48
Filed under: All, Programming, Python, wxPython

Here is how you convert a PNG image from a PIL (the Python Image Library format) object to a wxPython Image (or Bitmap) while keeping the alpha transparency layer.

Why convert? so you can use that bitmap to draw onto something like FloatCanvas.

from PIL import Image
import wx

pilImage = Image.open('my.png')
image = wx.EmptyImage(pilImage.size[0],pilImage.size[1])

## use the wx.Image or convert it to wx.Bitmap
bitmap = wx.BitmapFromImage(image)


Thats it. I hope that helps future googlers.

Subscribe via RSS ı Email
© 2016 - Jehiah Czebotar