HiDPI/Retina best practice?

Hi!

There are many related threads in the forum but searching for retina gives too many and old results. So I ask a new question…

Using older Xojo versions for a long time I switched now to the current Xojo 2017r2.1 on macOS 10.13.
After reading the DesktopHiDPISupport.pdf I got now following solution for a proper display in low and high resolution:
I created an image set containing the 1x and 2x PNG.
In the canvas I use

Sub Paint(g As Graphics, areas() As REALbasic.Rect) Handles Paint Dim p As picture = aboutPICT.BestRepresentation(Me.Width, Me.Height, Self.ScaleFactor) g.DrawPicture p, 0, 0, g.width, g.height, 0, 0, p.width, p.height End Sub

(“about” is the name of the image set)

This seems to work well but I’m not sure if there is no better way…
So my question is if the code above is correct or is there even a better way so that the proper image from an image set is used automatically based on the current screen resolution?

You can just use the picture object directly and Xojo will automatically utilize the correct image for the current display’s scaling factor.

There is no need to create a separate picture object §. Just draw using a reference to your image dragged into the IDE and Xojo automajically uses the proper pic for the screen

Strange. I tried this and it did not work as expected.
I check it again and report later my results.

Thanks.

You might want to try with a complete image set including the 3x image as well.

Not sure if it will make a difference in your case, but if we are discussing best practices then it’s worth noting.

It works fine now using the code

g.DrawPicture about, 0, 0

Where “about” is an image set with 1x and 2x images.

I guess it did not work before because the images had a wrong resolution.

Thanks for your help Jared and Roger.

[quote=354892:@Thomas Eckert]It works fine now using the code

g.DrawPicture about, 0, 0

Where “about” is an image set with 1x and 2x images.

I guess it did not work before because the images had a wrong resolution.

Thanks for your help Jared and Roger.[/quote]
I would suggest also, passing in the width and height of the picture.

g.drawpicture pic, left, top, width, height, 0, 0, pic.width, pic.height

based on what I got from a message from Greg… @3x is there only for iOS projects, and would be a waste of resources for a desktop project.

Might be useful for Windows, because of how it’s scaling engine working, but for the macOS (currently) @3x isn’t used.

Agreed. 3x versions are also handy in circumstances where you need to scale an image bigger than 2x. The framework would automatically use the larger image for you.

[quote=355011:@Sam Rowlands]I would suggest also, passing in the width and height of the picture.

g.drawpicture pic, left, top, width, height, 0, 0, pic.width, pic.height

If you simply want them drawn at native size, this is not necessary.