Transparent brush with wxGraphicsContext

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
bertolino
Experienced Solver
Experienced Solver
Posts: 77
Joined: Wed Aug 14, 2013 8:07 am
Location: France
Contact:

Transparent brush with wxGraphicsContext

Post by bertolino »

Hello,
I'm using a wxGraphicsContext to make some anti-aliased drawing in a bitmap.
I want to draw a kind of donut with the hole and the outside transparent.
All I can have is a donut with a black hole and a black outside. :-(
Here is my code (obviously, using the transparent brush is not the thing to do):

Code: Select all

bitmap.Create(9, 9);
wxMemoryDC dc(bitmap);
wxGraphicsContext *gc = wxGraphicsContext::Create(dc);
bool bAntiAlias = gc->SetAntialiasMode(wxANTIALIAS_DEFAULT);
wxPen pen(DONUT_COLOR, 2);
gc->SetPen(pen);
gc->SetBrush(*wxTRANSPARENT_BRUSH);
gc->DrawEllipse(0, 0, 9, 9);
dc.SelectObject(wxNullBitmap);
delete gc;
Any idea would be appreciated.
Best regards,

Pascal

Edit: Sorry for posting on the wrong forum
bertolino
Experienced Solver
Experienced Solver
Posts: 77
Joined: Wed Aug 14, 2013 8:07 am
Location: France
Contact:

Re: Transparent brush with wxGraphicsContext

Post by bertolino »

I kind of solved my issue.
The fact is that my bitmap was not managing transparency (i.e. the alpha channel).
So, I tried to initialize it from a PNG file (that manages transparency) and the code works great.
I did it with:

Code: Select all

bitmap= wxXmlResource::Get()->LoadBitmap(wxT("bitmap_in_png_file"));
Now I just have to create a 32 bit bitmap without the use of a file.
It shouldn't be tough.
Good night,

Pascal
Post Reply