drawing on wxDC with transparency

personaje personaje at gmail.com
Fri May 9 10:28:14 PDT 2008


On Thu, May 8, 2008 at 12:34 PM, Christopher Bruno
<cbruno.linux at gmail.com> wrote:
> 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.

This is a no-go for me as I can not assume that a color won't be used
when drawing.

The problem must lie in that wxMemoryDC does not propagate to the
alpha of the asociated bitmap.

regards


More information about the wx-users mailing list