Clear or erase wxBitmap Topic is solved

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
bluesnowball18
Earned a small fee
Earned a small fee
Posts: 13
Joined: Thu Apr 22, 2021 9:23 am

Clear or erase wxBitmap

Post by bluesnowball18 »

Is there an easy way to fill a rectangular area of wxBitmap or entire bitmap with transparent color?
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Clear or erase wxBitmap

Post by ONEEYEMAN »

Hi,
Convert it to image, set the transparency/alpha, then convert back.

How big is the bitmap?

Thank you.
bluesnowball18
Earned a small fee
Earned a small fee
Posts: 13
Joined: Thu Apr 22, 2021 9:23 am

Re: Clear or erase wxBitmap

Post by bluesnowball18 »

It can have any size up to 4096*4096 pixels.
User avatar
doublemax@work
Super wx Problem Solver
Super wx Problem Solver
Posts: 474
Joined: Wed Jul 29, 2020 6:06 pm
Location: NRW, Germany

Re: Clear or erase wxBitmap

Post by doublemax@work »

How time critical is the operation and how often do you have to do it?
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Clear or erase wxBitmap

Post by ONEEYEMAN »

Hi,
Are you targetting Windows only or you want it cross-platform?

Thank you.
bluesnowball18
Earned a small fee
Earned a small fee
Posts: 13
Joined: Thu Apr 22, 2021 9:23 am

Re: Clear or erase wxBitmap

Post by bluesnowball18 »

I think I've found a solution. Thank you for the responses.

Code: Select all

wxImage image("image.jpeg");
image.InitAlpha();

this->bitmap = wxBitmap(image);

Code: Select all

wxMemoryDC dc(this->bitmap);

dc.SetLogicalFunction(wxCLEAR);
dc.DrawRectangle(100, 100, 40, 20);
Post Reply