Re: [wxPython-users] A question on wxPython + PIL and a possible
bug
by Shane Holloway (IEEE) other posts by this author
Apr 15 2003 4:13PM messages near this date
Re: [wxPython-users] A question on wxPython + PIL and a possible
bug
|
[wxPython-users] Accessing the windows registry
In wx, bitmap masks are monochrome bit masks. If the value of the bit
is 1, then the bitmap pixel is painted. If it is 0, then the
destination pixel is left alone. What you have in the image's alpha
channel is a blending factor of source and destination:
color = src.color*(1-src.alpha) + dst.color*src.alpha
(where X.color is a vector of RGB color information, and
source.alpha = A / 255.)
Note that alpha channels can implement bitmasks, but can also do a lot
more in the way of blending two images.
Now, as for alpha blending support in wx, I have not seen it; but the
support *is* in PIL. My first guess at the process would be to capture
the draw event, copy the existing bitmap into a PIL canvas, do the
blending in PIL, copy the PIL data into an image and then a bitmap, then
blit the resultant bitmap on in the appropriate place. Sounds painful!
But it wouldn't be as bad if you could do all of the drawing in PIL though.
So, in conclusion, I don't think there's a way to do it in wx, but there
is a path in PIL, albeit a long one.
Good luck!
-Shane
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.
>
> 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@[...].org
>
>
---------------------------------------------------------------------
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)
|