Draw a Mask image to another mask

Odd one…
A mask is a picture.

So if I have picture1 with a mask
and picture2 with no mask, of the same size.

I should be able to

picture2.mask = new picture (picture2.width,picture2.height,32)
picture2.mask.graphics.drawpicture  picture1.mask,0,0,picture2.width,picture2.height,0,0,picture1.width, picture1.height

and end up with a mask on picture 2 which is the same as the mask on picture 1?

But when I tried it, I end up with an all white mask on the new picture, which is incorrect, and I am struggling to do what I need to do.

I got some success using

picture2.mask = picture1.mask

but I’m wary … that feels like a memory leak-in-waiting, or a crash later on…

If it makes a difference, this is Xojo 2015 on Windows

Try ApplyMask

Is your original mask in picture1 or in picture1.mask?
(your “A mask is a picture” statement let me think your mask is drawn directly in picture1, not its mask :man_shrugging:)

example of the scenario:
Picture1 is a photo of an apple.
It has a mask which correctly masks the apple
The mask is (obviously??) a picture in its own right, although a mask doesnt have its own mask.

So we have Picture1 with both Picture and Mask which I can see in the debugger.

Picture2 is (for example) a face, of the same dimensions.
It has no mask.

I issue
Picture2.mask = new picture( picture2.width, picture2.height, 32)

Now it has a mask
I issue
picture2.mask.graphics.drawpicture picture1.mask,0,0 etc

The result is that in the debugger, picture2.mask is pure white.
(Sometimes I think I saw Picture2 become white also … almost as if the drawing went to the picture graphics, not the mask)

I haven’t tried ApplyMask yet, but from the documentation it also wants to be passed a picture, so I’m not hopeful.

The results in the debugger don’t have to be correct. At least I remember a bug report where I had some nice black in black drawing.

1 Like

True.
But the on-screen result when I later tried to draw Picture2 was incorrect.
I only started looking in the debugger after several WTF moments.

Update:

picture2.applymask picture1.mask

…generates an unsupported operation exception
Looks like a mask isnt ‘quite’ a valid picture even if it is created in the same way as one.

You have to use

ResultPicture.ApplyMask OriginalPicture.CopyMask

1 Like

Thanks Beatrix.