Re: [wxPython-users] A question on wxPython + PIL and a possible
bug
by Robin Dunn other posts by this author
Apr 15 2003 9:26PM messages near this date
[wxPython-users] Re: A question on wxPython + PIL and a possible bug
|
Re: [wxPython-users] A question on wxPython + PIL and a possible
bug
Alberto Griggio wrote:
> 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.
It has now. Thanks.
>
> 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.
Not currently, but 2.5 is getting alpha support in wxImage and wxBitmap,
as well as some other nice image/bitmap enhancements...
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!
---------------------------------------------------------------------
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)
|