I guess I can distill it down a bit more. Here’s a function that will take a picture and create an appropriate mask:
Private Function createMaskPicture(source as Picture) As Picture
if source = nil then Return nil
var result as new Picture( source.Width, source.Height )
result.HorizontalResolution = source.HorizontalResolution
result.VerticalResolution = source.VerticalResolution
var g as Graphics = result.Graphics
g.ScaleX = source.Graphics.scaleX
g.ScaleY = source.Graphics.scaleY
Return result
End Function
Then used likes this:
Sub Paint(g As Graphics) Handles Paint
var p as Picture = new Picture( avatar.Width, avatar.Height )
p.Graphics.DrawPicture( avatar, 0, 0 )
var mask as Picture = createMaskPicture( p )
if mask <> nil then
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 )
end if
g.DrawPicture( p, 0, 0 )
End Sub