drawing on wxDC with transparency

personaje personaje at gmail.com
Wed May 7 08:57:33 PDT 2008


Hello everyone,

   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? Is
the wxDC not modifing the mask associated with the bitmap? Should I
draw the mask also?

   My code is something like this:

wxBitmap *pPaintedBitmap_ = new wxBitmap(x,y);
wxDC *pDeviceContext_ = new wxMemoryDC;

// not exactly right but it shouldnt be the problem right?
char *pbits = new char[x*y];
for (int i=0;i<x*y;i++)
	pbits[i] = 0;

wxBitmap bitmask(pbits,x,y,1);
wxMask *pmask = new wxMask(bitmask);
pPaintedBitmap_->SetMask(pmask);
pDeviceContext_->SelectObject(*pPaintedBitmap_);
pDeviceContext_->SetBrush(*wxTRANSPARENT_BRUSH);
wxPen Pen = *wxThePenList->FindOrCreatePen(wxColour(255,0,0),1,wxSOLID);
pDeviceContext_->SetPen(Pen);

/* ... Draw using pDeviceContext_->DrawPoligon() */

pDeviceContext_->SelectObject(wxNullBitmap);
delete pDeviceContext_;
pPaintedBitmap_->SaveFile("paintedbmp.png",wxBITMAP_TYPE_PNG);
delete pPaintedBitmap_;

with pbits initialized with 0 I get the polygon I draw, with the color
I selected and everything else black, alpha is 255 for all the image.
instead if I initialize pbits 255 I get RGB = 321 and alpha 0 for all the image.

I am going crazy here. can someone point me to the right direction?

Thanks
Regards.


More information about the wx-users mailing list