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:
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.
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>
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:
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.
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 Cornice - a cross platform image viewer </spam>
Alberto
---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org
[...]
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
Thanks for the explaination. I was looking exactly for this kind of
answer. As you may have guessed, I'm not very experienced with image
manipulations, so my terminology (and understanding of what was going on)
was quite unprecise... but you definitely pointed me into the right
direction, thanks!
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:
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.
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...
This is good news, great!
Anyway, in the meantime I found something slightly better: I'm not
following the "alpha blendnig road" anymore, it's too weird for my
limited skills at the moment, but I found a decent compromise.
The solution is to use a threshold value when converting the alpha
channel to a monochrome, so that values < 128 become black, and the
others white:
Now, another question: you mentioned some image enhancements: will they
allow us not to rely on the PIL anymore for complex manipulations? In
particular, is there some support for better image scaling and lazy
image loading (i.e. loading and rendering the image in small chunks)?
Now, another question: you mentioned some image enhancements: will they
allow us not to rely on the PIL anymore for complex manipulations? In
particular, is there some support for better image scaling and lazy
image loading (i.e. loading and rendering the image in small chunks)?
Probably not, but there is talk of yet another image class for doing the advanced stuff. So far it is just talk though.
OTOH, the raw bitmap access will probably allow for dumping the image data from a PIL image directly into a wxBitmap...
···
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!