|
From: Kevin A. <al...@se...> - 2001-09-14 21:18:38
|
Cliff Wells [log...@ea...] passed on some code that he
uses to convert between PIL and wxImage formats. Given the large number of
image manipulation routines in PIL, any wrapper classes we do for PythonCard
will probably use PIL or at least provide easy translation to and from PIL.
def PILToWX(image):
"convert a PIL image to a wxImage"
if (image.mode != 'RGB'):
image = image.convert('RGB')
imageData = image.tostring('raw', 'RGB')
imageWx = wxEmptyImage(image.size[0], image.size[1])
imageWx.SetData(imageData)
return imageWx
def WXToPIL(image, mode = 'RGBA'):
"convert a wxImage to a PIL RGBA image"
imageData = image.GetData()
size = (image.GetWidth(), image.GetHeight())
imagePIL = Image.fromstring('RGB', size, imageData)
if mode != 'RGB':
imagePIL = imagePIL.convert(mode)
return imagePIL
Here are some resources I mentioned previously, but are worth mentioning
again.
Python Imaging Library (PIL)
documenation in HTML and PDF formats, plus some PIL articles
http://www.pythonware.com/library/index.htm
source and binary distributions
http://www.pythonware.com/downloads/index.htm
wxPyWiki Working With Images
http://wxpython.org/cgi-bin/wiki/WorkingWithImages
ka
|