Icon Overlay - Retina

Hello, I do not use image sets but only a picture in any size
and scale it accordingly to my desired size.
I have 50 pictures in my list box and see no difference between
normal and HIDPI

Set picture 500x500 pixels in listbox size 45X40 pixels

Listbox1.Open
myicon= new Picture(100,40,32)
myicon.Graphics.DrawPicture lassoblau500,50,0,45,40,0,0,lassoblau500.Width,lassoblau500.height
myicon.Graphics.ForeColor = RGB(0,0,0)
myicon.Graphics.textsitze = 20
myicon.Graphics.drawstring(“Lasso”,55,15)
Listbox1.RowPicture(1) =myicon

…… and more

also goes in Bevelbutten or
in paint

[quote=413863:@Rudolf Jackel]Hello, I do not use image sets but only a picture in any size
and scale it accordingly to my desired size.
I have 50 pictures in my list box and see no difference between
normal and HIDPI

Set picture 500x500 pixels in listbox size 45X40 pixels

Listbox1.Open
myicon= new Picture(100,40,32)
myicon.Graphics.DrawPicture lassoblau500,50,0,45,40,0,0,lassoblau500.Width,lassoblau500.height
myicon.Graphics.ForeColor = RGB(0,0,0)
myicon.Graphics.textsitze = 20
myicon.Graphics.drawstring(“Lasso”,55,15)
Listbox1.RowPicture(1) =myicon

…… and more

also goes in Bevelbutten or
in paint[/quote]
And you can certainly do that, but you’re missing out on the optimizations that the Xojo framework does for you. For instance, this code will only ever create a 1x image, so on macOS Retina screens and on Windows with scale factors > 100% the image will look pixelated or blurry.

[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]

Greg:
in short, there are two Pictures kinds:

a. Picture(0): A Picture with one image in it,
b. Picture(2): An indexed Picture with three images in it 1x, 2x, 3x).

I use the word image above just to not use two times Picture.

Only problem is I already have from many years ago Pictures files with more than one Image in each files, usually with the same dpi. But this is hors context (not Xojo related).