It seems that Xojo uses images in 72 dpi but at double (and triple) points, see below.
So that’s what I did, but with different images (showing other things besides the size difference). Which lets me know which image was loaded (that my code is good).
I load the image in 2x, but it does not fit in the canvas which is at 1x size…
Sizes:
1x: 220 x 101 in 72 dpi
2x: 440 x 202 in 72 dpi
3x: 660 x 303 in 72 dpi
The destination Canvas is 220 x 101 in size. When loaded, my x2 image is a bit truncated.
The documentation doesn’t seem to agree…more or less…and I’m not talking about the Forum.
The question is: what can Xojo do behind my back to correctly display my image.
The sign at is not welcome by the forum software, so I replaced it with a ‘x’.
Are you using an Image set or are you using separate images?
Creating Image sets by using the Image Set Editor should handle the correct sizing of the images for you when running the application.
That is what I think, but reading this forum leads me to what I wrote above; the LR also says that, but recently adds 72 /144 / 216 dpi.
But this does not solve the problem.
In the screen shot where the feather is incomplete, the images comes from the hard disk.
In the other screen shot, taken from the IDE, the image comes from the Image Set Editor:
This is correct. Drawing at scale is not automatic. If pulling the images from disk, you’ll either want to load them into a multi-resolution picture, or use DrawPicture with the full scale parameters to draw it at the size you need. For a 2x image, you’d want to draw it at half the size. As counter intuitive as it sounds, it’ll maintain the high resolution. In my opinion an image set or multi red picture (which is all an image set is) is much easier to work with.
Wait, what?
If the OP has an image set, can they not just draw the image and Xojo (using Apple’s API) draws the correct image for the display?
Almost all of my image drawing code uses declares and NSImages, which auto handles this, but it is still important to include the full draw rect and not just a draw point.
A lot of the UI images you see in my apps are imagewells (with declares to hide the frame and control the image scaling), with setting a NSImage into the ImageWell.
I loaded the correct image with code and get wrong results.
To be sure it is not me, I created a Picture set and get the correct result.
BUT I DO NOT WANT TO EMBED THE IMAGES IN MY PROJECT…
This is simple.
And I do nothing fancy: not MY bug !
Here’s the used code:
//
//
Var Image_FI As FolderItem
Var Image_Name As String
Select Case Self.ScaleFactor
Case 1
Image_Name = "sqlite370_banner.png"
Case 2
Image_Name = "sqlite370_banner@2.png"
Case 3
Image_Name = "sqlite370_banner@3.png"
Else
Image_Name = "sqlite370_banner.png"
End Select
// Get a Reference to the Resources Folder
Image_FI = App.ExecutableFile.Parent.Parent.Child("Resources")
// Get a Reference to the Images Folder
Image_FI = Image_FI.Child("Images")
// Get a Reference to the correct image
Image_FI = Image_FI.Child(Image_Name)
// Assign l’image
Me.Backdrop = Picture.Open(Image_FI)
// Force a refresh to display the image (in case…)
Me.Invalidate
Var ResourcesFolder As FolderItem = App.ExecutableFile.Parent.Parent.Child("Resources")
Var BaseImage As Picture = Picture.Open(ResourcesFolder.Child("sqlite370_banner.png"))
Var Images() As Picture
Images.Add(BaseImage)
Images.Add(Picture.Open(ResourcesFolder.Child("sqlite370_banner@2.png")))
Images.Add(Picture.Open(ResourcesFolder.Child("sqlite370_banner@3.png")))
Me.Backdrop = New Picture(BaseImage.Width, BaseImage.Height, Images)
Method 2: Draw the picture at the desired size
Var BestFactor As Integer = Min(3, Ceiling(Self.ScaleFactor))
Var ImageName As String = "sqlite370_banner" + If(BestFactor = 1, "", "@" + BestFactor.ToString(Locale.Raw, "0")) + ".png"
Var Source As Picture = Picture.Open(App.ExecutableFile.Parent.Parent.Child("Resources").Child(ImageName))
Var Image As New Picture(Source.Width / BestFactor, Source.Height / BestFactor)
Image.Graphics.DrawPicture(Source, 0, 0, Image.Width, Image.Height, 0, 0, Source.Width, Source.Height)
Me.Backdrop = Image
Oh and also, you can’t count on ScaleFactor being whole numbers.
Edit: I’m writing code from memory, it may be necessary to set the resolution properties of the Image variable in the second example.
If you simply load the image from disk w/o using an image set and use it as a Canvas backdrop, make sure to set the images’ properties HorizontalResolution and VerticalResolution correctly. Simply multiply 72 with the current scaling for both. That should work.