drawing on wxDC with transparency

Xavier Miller xavier.miller at cauwe.org
Fri May 9 00:12:04 PDT 2008


Yes, that can work when you only have full transparent/full opaque 
elements to draw.

This becomes more funny when you want to insert into your memoryDC a 
bitmap with alpha channel and "progessive alpha zones".

Xavier.

Christopher Bruno a écrit :
> I solved this problem by using a wxMemoryDC to draw to a bitmap. First I 
> set the background colour to some odd colour that I will not use in my 
> drawing (the mask). Then I drew my picture with memDC to the bitmap, and 
> then converted the bitmap to a wxImage. I then wrote a function called 
> SetColourToAlpha(wxImage &, const wxColour & , int) that went through 
> and checked the colour at each pixel in the image. If the pixel RGB 
> value equaled the same as the mask colour, I set the alpha value to the 
> int passed at that pixel. Slow (w*h time), but it works. This will also 
> help you get translucency if you alpha value >  0. Remember to call 
> InitAlpha() on the wximage or it wont work
> 
> Your problem is that you set the alpha value for the image before you 
> draw, and never change it, so the parts you draw still cant be seen 
> (they have alpha 0). Set the alpha value after to draw to the parts you 
> want transparent. Hope that helps.
> 
> n! Labs
> 
> On Thu, May 8, 2008 at 9:25 AM, personaje <personaje at gmail.com 
> <mailto:personaje at gmail.com>> wrote:
> 
>     bump,
> 
>     any thoughts?
> 
>     On Wed, May 7, 2008 at 2:23 PM, personaje <personaje at gmail.com
>     <mailto:personaje at gmail.com>> wrote:
>      > On Wed, May 7, 2008 at 2:16 PM, Robert Roebling
>     <robert at roebling.de <mailto:robert at roebling.de>> wrote:
>      >  >
>      >  >  personaje wrote:
>      >  >
>      >  >  >    I want to draw on a  bitmap usign wxDC's primitives and keep
>      >  >  > everything transparent except for the parts I draw on
>     (using mainly
>      >  >  > DrawPolygon, with a wxPen and wxTRANSPARENT_BRUSH).
>      >  >  >
>      >  >  >    I am getting a completely transparent bitmap. I read on
>     the wxDC
>      >  >  > help page the note about Transparency / Alpha channel for
>     wxMAC. My
>      >  >  > question is: All other platforms don't support
>     transparency/alpha?
>      >  >
>      >  >  Consider using wxGraphicsContext,
>      >
>      >  is that because wxDC doesnt support what I am trying to do?
>      >  I am worried that I am doing something wrong that won't work
>     even with
>      >  wxGraphicsContext
>      >
>      >  Regards.
>      >
>     _______________________________________________
>     wx-users mailing list
>     wx-users at lists.wxwidgets.org <mailto:wx-users at lists.wxwidgets.org>
>     http://lists.wxwidgets.org/mailman/listinfo/wx-users
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> wx-users mailing list
> wx-users at lists.wxwidgets.org
> http://lists.wxwidgets.org/mailman/listinfo/wx-users


More information about the wx-users mailing list