How to change a masked bitmap to an alpha blended bitmap?

Phillip Piper wrote:

I have a masked bitmap, and I want to draw the masked part of the bitmap
translucently (e.g. alpha value of 64). Any ideas on how to do this?

Alpha blends do not take a mask into account; probably because you can
achieve the same thing via an alpha value of 255 (completely
transparent).

So, I could do something like this:

image = bitmap.ConvertToImage() alphaValues = chr(myAlphaValue) * ((bitmap.GetWidth() *
bitmap.GetHeight())
for i in range(image.GetMask().get_bit_count()):
  if not image.GetMask().is_bit_set(i):
    alphaData[i] = 255

But I'm stuck with this because I don't know how to get an image's mask
as a series of bits, or how to iterate over such a series.

In a wx.Image the mask is just managed as a specific colour value, so you can test if pixels in the image are masked something like this (totally untested, but it should at lest put you on the right track):

mr, mg, mb = (img.GetMaskRed(), img.GetMaskGreen(), img.GetMaskBlue())
for y in range(img.GetHeight()):
  for x in range(img.GetWidth()):
    if (mr, mg, mb) == (img.GetRed(x,y), img.GetGreen(x,y), img.GetBlue(x,y)):
      img.SetAlpha(x,y,255)

ยทยทยท

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