bitmaps and masks

Folks

I'm using bitmaps with masks so I can draw bitmaps on other bitmaps and see the colour through the overwritten bitmaps. My problem arises when I try to change the top bitmap. If I draw a line, the mask stops it being shown. What I would like is to get the mask bitmap and draw the same things on it in monochrome as the bitmap so it will show. Can I do this? wxMask doesn't have a GetBitmap function documentated.

Should I do this some other way? The working with images wiki was helpful but didn't address with issue.

Nigel

···

--
Nigel W. Moriarty
Building 4R0230, Physical Biosciences Division
Lawrence Berkeley National Laboratory
Berkeley, CA 94720-8235
Phone : 510-486-5709
Fax : 510-486-5909
Email : NWMoriarty@LBL.gov
Web : CCI.LBL.gov

Nigel Moriarty wrote:

Folks

I'm using bitmaps with masks so I can draw bitmaps on other bitmaps
and see the colour through the overwritten bitmaps. My problem
arises when I try to change the top bitmap. If I draw a line, the
mask stops it being shown. What I would like is to get the mask
bitmap and draw the same things on it in monochrome as the bitmap so
it will show. Can I do this? wxMask doesn't have a GetBitmap
function documentated.

No, but you can generate a bitmap of the mask something like this: Create a wx.Region using wx.RegionFromBitmap using the masked bitmap. Then make an empty bitmap of the same size and select it into a wx.MemoryDC. Set the brush to black and dc.Clear(). Then Set the ClippingRegion using the region you created before using dc.SetClippingRegionAsRegion(region), finally set the brush to white and do dc.Clear() again.

Should I do this some other way? The working with images wiki was
helpful but didn't address with issue.

If that works for you then please add it to the wiki

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin

At first it looked like mumbo-jumbo but it should work well. I haven't been
able to get a region from a bitmap. I'm using version 2.4.0.4 and the wxRegion
fails when passed a bitmap and wxRegionFromBitmap is not defined.

Is this a migration and/or version issue?

Nigel

···

On Wed, 21 Apr 2004 17:58:31 -0700 Robin Dunn <robin@alldunn.com> wrote:

Nigel Moriarty wrote:
> Folks
>
> I'm using bitmaps with masks so I can draw bitmaps on other bitmaps
> and see the colour through the overwritten bitmaps. My problem
> arises when I try to change the top bitmap. If I draw a line, the
> mask stops it being shown. What I would like is to get the mask
> bitmap and draw the same things on it in monochrome as the bitmap so
> it will show. Can I do this? wxMask doesn't have a GetBitmap
> function documentated.

No, but you can generate a bitmap of the mask something like this:
Create a wx.Region using wx.RegionFromBitmap using the masked bitmap.
Then make an empty bitmap of the same size and select it into a
wx.MemoryDC. Set the brush to black and dc.Clear(). Then Set the
ClippingRegion using the region you created before using
dc.SetClippingRegionAsRegion(region), finally set the brush to white and
do dc.Clear() again.

>
> Should I do this some other way? The working with images wiki was
> helpful but didn't address with issue.

If that works for you then please add it to the wiki

--
Nigel W. Moriarty
Building 4R0230, Physical Biosciences Division
Lawrence Berkeley National Laboratory
Berkeley, CA 94720-8235
Phone : 510-486-5709
Fax : 510-486-5909
Email : NWMoriarty@LBL.gov
Web : CCI.LBL.gov

Robin

I'm using 2.4.0.4 for our app release purposes, but wxRegion(bmp) fails and
there isn't wxRegionFromBitmap.

Help?

Nigel

···

On Wed, 21 Apr 2004 17:58:31 -0700 Robin Dunn <robin@alldunn.com> wrote:

Nigel Moriarty wrote:
> Folks
>
> I'm using bitmaps with masks so I can draw bitmaps on other bitmaps
> and see the colour through the overwritten bitmaps. My problem
> arises when I try to change the top bitmap. If I draw a line, the
> mask stops it being shown. What I would like is to get the mask
> bitmap and draw the same things on it in monochrome as the bitmap so
> it will show. Can I do this? wxMask doesn't have a GetBitmap
> function documentated.

No, but you can generate a bitmap of the mask something like this:
Create a wx.Region using wx.RegionFromBitmap using the masked bitmap.
Then make an empty bitmap of the same size and select it into a
wx.MemoryDC. Set the brush to black and dc.Clear(). Then Set the
ClippingRegion using the region you created before using
dc.SetClippingRegionAsRegion(region), finally set the brush to white and
do dc.Clear() again.

>
> Should I do this some other way? The working with images wiki was
> helpful but didn't address with issue.

If that works for you then please add it to the wiki

--
Nigel W. Moriarty
Building 4R0230, Physical Biosciences Division
Lawrence Berkeley National Laboratory
Berkeley, CA 94720-8235
Phone : 510-486-5709
Fax : 510-486-5909
Email : NWMoriarty@LBL.gov
Web : CCI.LBL.gov

Nigel Moriarty wrote:

Robin

I'm using 2.4.0.4 for our app release purposes, but wxRegion(bmp) fails and there isn't wxRegionFromBitmap.

Help?

wxRegionFromBitmap was added later, maybe in 2.4.1 but more likely in 2.4.2.

The only other way I can think of (there might be others) to do what you are needing is to convert the bitmap to a wxImage. The mask should be preserved by changing pixel values to a colour reserved for the mask, and you can then traverse the pixels in the image checking for the mask colour, and build another image or a region that way.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!