.Mask versus .CopyMask

The deprecation list tells me that instead of .Mask I should use .CopyMask. However, when I do that I only get a NilObjectException and I don’t see anything nil.

Old code:

[code]static p As Picture
if p = nil or p.Width <> Width or p.Height <> Height then
p = new Picture(Width , Height , 32) //Mask

dim gg As Graphics = p.Mask.Graphics[/code]

If I use p.CopyMask.Graphics in the last line I get a NOE. However both p and p.CopyMask are not nil.

If I compare the result of .Mask and .CopyMask with

dim p1 as Picture = p.mask dim p2 as Picture = p.CopyMask

I don’t see a difference. Am I doing something wrong?

Xojo 2019r2 with High Sierra.

Hallo Beatrix,
nach einigen Versuchen habe diese Methode in API2 übernommen
applymask() setzt Maske

rem erstelle Shape aus Bild - rund oder Stern4
Var neu As New picture(200,200)
Var neu2 As New picture(200,200)
Var stern(-1) As Integer
stern = Array(0,100,0,120,80,200,100,120,120,100,200,80,120,0,100,80,80) // 4 er Stern

neu.Graphics.drawpicture meinBild,0,0,200,200,550,200,600,600 // Bild Ausschnitt

neu2= neu.CopyMask
neu2.Graphics.DrawingColor = HSV(0,0,0,0)
// neu2.Graphics.fillOval(0,0,200,200)
neu2.Graphics.FillPolygon stern

px = New PixmapShape(neu)

rem px ist bei mir ein globales Pixmapshape und kann mit px.rotation oder px.scale gut angepasst werden

Thanks, Rudolf. I’m a lazy developer and wanted to simply do a replace from .Mask to .CopyMask and not do a review of all the 419 occurrences of .Mask. .CopyMaskMBS works but I don’t understand why .CopyMask doesn’t.

Mask is for pictures created with new picture(w, h, 32)
CopyMask if for pictures created with new picture(w, h)

this is also for API1

What API2 add is to deprecate mask and so picture(w, h, 32) when used for this at least

To check this in a pre API2 or API2 Xojo release try this code

Dim p1 As New Picture(20, 20, 32)
Dim m1 As Picture=p1.CopyMask
Dim mm1 As Picture=p1.Mask

Dim p2 As New Picture(20, 20)
Dim m2 As Picture=p2.CopyMask
Dim mm2 As Picture=p2.Mask

at break point in every release you will find
m1 nil (copyMask for a picture with deep size) and mm2=nil (mask for a modern picture)

This is an old change

what’s new is the deprecation

1 Like

.Mask is essentially a second picture used to mask your image. CopyMask does something similar, but it returns a new picture with the contents of your picture’s alpha channel. Changing the returned picture has no result on your original picture. You can use ApplyMask to essentially put it back, including applying it multiple times on other pictures.

Thanks, Thom and Antonio for the explanations. The deprecation warning then is a really bad idea.