It depends on how you’re constructing your picture object. It’s going to vary based on the source. Immutable picture objects (such as those you drag in to the project) cannot have a mask applied directly, so you’ll need an intermediate picture object.
You then need to construct your mask Picture to match the Picture it’s being applied to, which is a bit of a pain. You need to handle the X/Y scaling factors and the Horizontal and Vertical resolutions.
In this example, I’m using an image dragged in to the project named “avatar”
Sub Paint(g As Graphics) Handles Paint
var p as new Picture( avatar.Width, avatar.Height )
p.Graphics.DrawPicture( avatar, 0, 0 )
var mask as new Picture( p.Width, p.Height )
mask.HorizontalResolution = p.HorizontalResolution
mask.VerticalResolution = p.VerticalResolution
var m as Graphics = mask.Graphics
m.ScaleX = g.ScaleX
m.ScaleY = g.ScaleY
m.DrawingColor = &cffffff
m.FillRectangle( 0, 0, m.Width + 10, g.Height )
m.DrawingColor = &c000000
m.FillOval( 0, 0, m.Width, m.Height )
p.ApplyMask( mask )
g.DrawPicture( p, 0, 0 )
End Sub
It’s a bit easier if you’re drawing the initial Picture in Xojo because both will be setup identically by the framework, but you may still wish to use the above bit of code. Here’s a simple one for a source image created using Xojo:
Sub Paint(g As Graphics) Handles Paint
var p as new Picture( 256, 256 )
p.Graphics.DrawingColor = &cff0000
p.Graphics.FillRectangle( 0, 0, p.Graphics.Width, p.Graphics.Height )
var mask as new Picture( p.Width, p.Height )
var m as Graphics = mask.Graphics
m.DrawingColor = &cffffff
m.FillRectangle( 0, 0, m.Width + 10, g.Height )
m.DrawingColor = &c000000
m.FillOval( 0, 0, m.Width, m.Height )
p.ApplyMask( mask )
g.DrawPicture( p, 0, 0 )
End Sub
I use the first implementation I provided above and have a Shared Method on a common subclass called BitmapForCaching (to match the desktop implementation that has this done for you as a member of the DesktopWindow class), and another that will accept a picture as parameter then construct and return an appropriate mask Picture for it as well as a mutable Picture (just a copy of the original).