How to use a Picture with Mask as another picture's Mask

Suppose I have a class Picture (no alpha) that contains an image in the center.
I also have a B&W mask set on the picture that makes part of the image transparent.

I now like to get a single mask-less picture that has the mask applied. I.e., I like to get a Picture that contains the same as what I’d see if I drew the picture onto a white canvas.

How can I accomplish that?

(I need this because I want to use the result as a mask for another Picture, so it has to be a flattened picture without an explicit mask).

The Help says I should simply draw the masked image into a new alpha-based Picture. But that doesn’t work correctly: The mask is not getting applied, then.

so you want to take the MASK (B&W or grayscale???) and "apply it to the picture layer? and then remove the mask layer?
So that those areas where the mask made transparent, the picture layer is white? is that correct?

probably the easiest way is to get the RGBSurface of both layers and based on the pixel of the Mask, either leave the Picture layer pixel alone, or set it to white… even a large image should only take a few seconds or less

Dave, yes, you understood my correctly. However, I have to process dozens of pictures within less than a second, so going over every pixel is not an option.

But after some more digging I found the solution:

' flatten the mask dim flattenedPic as new Picture (maskedPic.Width, maskedPic.Height) dim mg as Graphics = flattenedPic mg.ForeColor = &cFFFFFF00 mg.FillRect 0, 0, maskedPic.Width, maskedPic.Height mg.DrawPicture (maskedPic, 0, 0)

The part that I was missing before is that I had to first paint the image white. Now it works.

then read the LR… there is a faster way to replace the mask than this… I don’t recall the exact syntax… ApplyMask or something

I’m pretty sure you don’t even need the fill. It starts transparent anyway. Otherwise, that is precisely how I’d do it.

After some more thought given to this, here’s why I need the fill: As I wrote, I need to use the result as a mask for another picture. And for that, the picture must not have any transparency (because that’s ignored when used as a mask) but instead must be white where it would be transparent.

So, generally speaking, the fill would not be necessary, but for my case as I described it in the question, it is. I shall update the topic line now accordingly.

Oh my mistake. I read FFFFFF00 as “white with no opacity” which is just translucent. I forgot that Xojo uses the last parameter as amount of transparency instead of amount of opacity.

This sounds interesting!

But, I think this would be a “type mismatch error”:

dim mg as Graphics = flattenedPic

Is there missing a piece of code? Or is it possible to access a picture from Graphics?

It was meant to be

dim mg as Graphics = flattenedPic.Graphics