[wxPython-users] A question on wxPython + PIL and a possible bug
by Alberto Griggio other posts by this author
Apr 15 2003 10:44AM messages near this date
Re: [wxPython-users] Question re right-aligned text control
|
[wxPython-users] Re: A question on wxPython + PIL and a possible bug
Hello everybody,
first I wanted to report what it seems a bug to me: according to the
doc, wx.Timer.Start returns True or False depending on the success of
the operation. But here (wxPython 2.4.0.6 GTK - but I think also MSW)
it always returns None. I can't test it on 2.4.0.7 at the moment, so
sorry if it has been already fixed.
Now, the question. I'm using wxPython together with the PIL to handle
images. Browsing the wiki, I found that the suggested way to get a
wx.Bitmap from a PIL image is:
img = wx.EmptyImage(*pil_image.size)
img.SetData(pil_image.convert('RGB').tostring()) bmp =
wx.BitmapFromImage(img)
This works like a charm on most cases, but if the image is originally
in RGBA format, it causes a loss of information. This is annoying when
the image has transparency, since it is completely lost.
As a workaround, I'm doing something like:
if pil_image.mode == 'RGBA':
alpha = pil_image.split()[3]
mask = wx.EmptyImage(*alpha.size)
mask.SetData(alpha.convert('1').convert('RGB').tostring())
bmp.SetMask(wx.Mask(wx.BitmapFromImage(mask, 1)))
But the results are not perfect (see
http://web.tiscali.it/agriggio/wx_pil.html)
So I'd like to know if there's a better way to do this.
Thanks in advance.
<spam>
You can safely stop reading here ;-) I'm asking this because I'm
writing an image viewer. If you want to try it out, you can get it at
http://web.tiscali.it/agriggio/cornice.html </spam>
Alberto
---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@[...].org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org
Thread:
Alberto Griggio
Alberto Griggio
Robin Dunn
Alberto Griggio
Robin Dunn
Shane Holloway (IEEE)
|