MutableBitmap with mask

I’m still confused by HiDPI. But there are only a couple of issues to be solved.

The HiDPI guide and the documentation is totally silent on how to create a MutableBitmap. I found CopyColorChannels in my code to do a MutableBitmap. But how to I add a mask?

Original code:

[code]dim theUtility as picture

if theName = “action” then
theUtility = new Picture(action.Width, action.Height, 32)
theUtility.Graphics.DrawPicture(action, 0, 0)
theUtility.Mask.Graphics.DrawPicture(action.Mask, 0, 0)
'other pics
end if[/code]

The HiDPI guide tells me I need to create a MutableBitmap but is quite silent on how to create one. Is there a less silly way to do this?

[code]dim theUtility, theUtilityMutable as picture

if theName = “action” then
theUtility = new Picture(action.Width, action.Height, 32)
theUtility.Graphics.DrawPicture(action, 0, 0)

theUtilityMutable = New Picture(theUtility.Width, theUtility.Height, 32)
theUtilityMutable = theUtility.CopyColorChannels
theUtilityMutable.Mask.Graphics.DrawPicture(action.Mask, 0, 0)
end if[/code]

Anyways, the mask is empty. How do I add a mask? The picture is going to inserted into another picture so I need the mask.

Picture.CopyMask and Picture.ApplyMask.

ApplyMask applies the mask but doesn’t add the mask to the picture as actual mask. And ApplyMask crashes hard. feedback://showreport?report_id=52732

As far as I can see Xojo with HiDPI doesn’t want to let me muck around with masks at all. I think I can see where my code has gone wrong. Here I don’t need a mask at all. But I don’t see where I would draw the mask if I needed one.

Images for HiDPI (like the ones built in the IDE) are multi representation images. That is, they have more than one picture at different resolutions inside them, so copymask and applymask won’t work directly on them.

The trick is that you either need know which resolution you need, or to convert all of the pictures in the image. If your method is used directly from a window or a canvas, you can access Window.ScaleFactor or Canvas.ScaleFactor or in the PaintEvent, you can even look at Graphics.ScaleX and Graphics.ScaleY to determine the scale factor of the screen that the current window lies on.

Did you get a picture when you called CopyMask?

The first piece of code can’t work because I have an Immutable Picture and not a Mutable one. It’s not clear to me what is happening in the second piece. I learned that CopyColorChannels makes a Mutable picture. I still don’t know how to make a Mutable Picture in a more sensible manner - but this is less the problem here.

Can I expect Xojo to pick the correct representation when I talk to the “action” picture? Should the debugger show me a picture with a mask after telling the picture to draw one? Should I see a mask in the debugger after using “ApplyMask”?

Is it better not to talk to “action” directly when doing something slightly more complicated but the IndexedImage(i)? Are you saying the same above?

I’m expecting my old code to work which is obviously a bad idea. However, I think that Xojo is trying to hide complexity and this confuses me. Time to stop for today.