ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> wxPython-users
wxPython-users
[wxPython-users] Re: A question on wxPython + PIL and a possible bug
by Alberto Griggio other posts by this author
Apr 16 2003 11:38AM messages near this date
[wxPython-users] A question on wxPython + PIL and a possible bug | Re: [wxPython-users] Re: A question on wxPython + PIL and a possible bug
> > Now, the question. 
[...]
> > 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...

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:

     if pil_image.mode == 'RGBA':
         alpha = pil_image.split()[3]
         mask = wx.EmptyImage(*alpha.size)
         mask.SetData(alpha.point([0]*128 + [255]*128, 
                                  '1').convert('RGB').tostring())
         bmp.SetMask(wx.Mask(wx.BitmapFromImage(mask, 1)))

With this the mask obtained is the "right" one.


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)?


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)

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved