Drawing on a wxBitmap which already has a mask  [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.
mael15
Super wx Problem Solver
Super wx Problem Solver
Posts: 279
Joined: Fri May 22, 2009 8:52 am
Location: Bremen, Germany

Drawing on a wxBitmap which already has a mask

Postby mael15 » Wed Nov 07, 2018 5:24 pm

I want to draw something on a wxBitmap which has a wxMask. Obviously the drawing does not show if it is made in the masked region. So what can I do? Somehow change the mask parallel to the drawing? Revert the wxMask to an unused colour, delete the mask, paint and then set a new wxMask with this unused colour?!
Thanx!

EDIT: When I destroy a wxMask its area appears to become wxBLACK. Can I change it so it becomes an unused colour? The wxBitmap i want to draw on has parts drawn in wxBLACK already.

User avatar
doublemax
Moderator
Moderator
Posts: 12755
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Drawing on a wxBitmap which already has a mask

Postby doublemax » Wed Nov 07, 2018 5:44 pm

I've never done this, but my first idea would be:

Code: Select all

// get mask as monochrome bitmap if you need it for later
wxBitmap save_mask = bitmap.GetMask()->GetBitmap();

bitmap.SetMask( NULL);
// draw on bitmap

// create new mask here
Use the source, Luke!

mael15
Super wx Problem Solver
Super wx Problem Solver
Posts: 279
Joined: Fri May 22, 2009 8:52 am
Location: Bremen, Germany

Re: Drawing on a wxBitmap which already has a mask

Postby mael15 » Wed Nov 07, 2018 5:53 pm

interesting, so I guess i get a 1bit wxBitmap from the mask, do the same painting on it like i do on the "real" bitmap only in black/white and then reapply the mask? :?:

User avatar
doublemax
Moderator
Moderator
Posts: 12755
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Drawing on a wxBitmap which already has a mask

Postby doublemax » Wed Nov 07, 2018 7:25 pm

mael15 wrote:interesting, so I guess i get a 1bit wxBitmap from the mask, do the same painting on it like i do on the "real" bitmap only in black/white and then reapply the mask? :?:
I think i haven't fully understood what you're trying to do. Isn't clearing the old mask, drawing and then creating a new mask all you need? Or do you need to merge the previous and the new mask somehow because a new mask can't be created from the new bitmap content alone?
Use the source, Luke!

mael15
Super wx Problem Solver
Super wx Problem Solver
Posts: 279
Joined: Fri May 22, 2009 8:52 am
Location: Bremen, Germany

Re: Drawing on a wxBitmap which already has a mask

Postby mael15 » Wed Nov 07, 2018 8:05 pm

When I delete the old mask, the formerly masked regions seem to become black. This is a problem because I have black drawings on the bitmap. So I was hoping to keep the mask data somehow? Or find a way that deleting the mask does not result in black pixels?

User avatar
doublemax
Moderator
Moderator
Posts: 12755
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Drawing on a wxBitmap which already has a mask

Postby doublemax » Wed Nov 07, 2018 9:28 pm

Or find a way that deleting the mask does not result in black pixels?
Interesting, I had no idea that happens. I'd have to make some experiments myself. In the worst case, you'll have to keep a copy of the unmodified bitmap before applying the mask.
Use the source, Luke!

mael15
Super wx Problem Solver
Super wx Problem Solver
Posts: 279
Joined: Fri May 22, 2009 8:52 am
Location: Bremen, Germany

Re: Drawing on a wxBitmap which already has a mask

Postby mael15 » Thu Nov 08, 2018 11:37 am

okay, seems like the pixels do not become black but only look black because it is the default colour. I have to make some more tests myself to get to the bottom of this. :-k

mael15
Super wx Problem Solver
Super wx Problem Solver
Posts: 279
Joined: Fri May 22, 2009 8:52 am
Location: Bremen, Germany

Re: Drawing on a wxBitmap which already has a mask  [SOLVED]

Postby mael15 » Thu Nov 08, 2018 4:54 pm

Sorry about this confusion, it seems I have some weird behaviour that has nothing to do with wxWidgets.
For others who might get into a similar situation: It works just fine like this:

Code: Select all

wxColour maskColDetected;
wxMemoryDC temp_dc;
wxBitmap *btmp = getBitmapWithMask();
// delete old mask
btmp->SetMask(nullptr);
temp_dc.SelectObject(*btmp);
temp_dc.GetPixel(0, 0, &maskColDetected);   // i never paint on wxPoint(0, 0), so it is the mask colour
// do drawing
temp_dc.SelectObject(wxNullBitmap);
btmp->SetMask(new wxMask(*btmp, maskColDetected));


Return to “C++ Development”

Who is online

Users browsing this forum: No registered users and 24 guests