[quote=413825:@Greg O’Lone]Ok, here’s a project which includes an extension method which allows you to overlay pictures & images onto one another.
https://www.dropbox.com/s/ftt08tdl4jq6bfl/ImageOverlayTest.zip?dl=1
Look at the Window1.Canvas1.Paint event to see how it’s used.[/quote]
Just in case this project doesn’t exist in the future, here’s the method:
[code]Public Function OverlayPic(extends pic as picture, overlay as picture, x as Integer = 0, y as Integer = 0, width as integer = -1, height as integer = -1) as Picture
// If the supplied picture contains more than one bitmap, call recursively
If pic.ImageCount > 0 Then
Dim pics() As Picture
For i As Integer = 0 To pic.ImageCount - 1
pics.Append pic.IndexedImage(i).OverlayPic(overlay)
Next
Return New Picture(pic.Width, pic.Height, pics)
End If
Dim newpic As picture
// Create the same type of picture that we started with
If pic.HasAlphaChannel Then
newpic = New picture(pic.Width, pic.Height)
Else
newpic = New picture(pic.Width, pic.Height, 32)
End If
// Transfer the horizontal and vertical resolutions
newpic.HorizontalResolution = pic.HorizontalResolution
newpic.VerticalResolution = pic.VerticalResolution
// Transfer the graphics scale
Dim g As Graphics = newpic.Graphics
If pic.Graphics <> Nil Then
g.scaleX = pic.Graphics.ScaleX
g.scaleY = pic.Graphics.ScaleY
Else
g.scaleX = pic.horizontalResolution / 72
g.ScaleY = pic.verticalResolution / 72
End If
// If the original picture has a mask, set its scale as well
If pic.HasAlphaChannel = False Then
newpic.Mask.graphics.scaleX = g.scaleX
newpic.Mask.graphics.scaleY = g.scaleY
End If
// Transfer the color portion of the original picture
newpic.Graphics.DrawPicture pic.CopyColorChannels, 0, 0
// Transfer the alpha or mask of the original picture
If pic.HasAlphaChannel Then
newpic.ApplyMask pic.CopyMask
Else
newpic.Mask.graphics.drawpicture pic.CopyMask, 0, 0
End If
// Finally draw the overlay
// With the horizontal and vertical resolutions and Graphics.ScaleX/Y set, the Xojo Framework will select the right image to draw
If width = -1 Then width = overlay.Width
If height = -1 Then height = overlay.Height
newpic.Graphics.DrawPicture overlay, x, y, width, height, 0, 0, overlay.Width, overlay.Height
Return newpic
End Function
[/code]