HiDPI Images from disk

Up until this point in my project, I’ve been using ImageSets in the IDE by dragging three images (@1x, @2x and @3x) into the image set editor. This works great.

Moving forwards, I want to be able to load images from disk stored in my app’s Resources folder. What is the best way to load the correct sized image this way?

For future reference, Norman Palardy helped me figure this out off-list:

Protected Function ImageFromResources(imageName as string) as Picture
  Var resourcesFolder As FolderItem = SpecialFolder.Resources
  If resourcesFolder Is Nil Then
    Var tmp As New NilObjectException
    tmp.Message = "Resources folder is nil or not readable"
    Raise tmp
  End If
  
  Var image1xFile As Folderitem = resourcesFolder.Child(imageName+".png")
  Var image2xFile As Folderitem = resourcesFolder.Child(imageName+"@2x.png")
  Var image3xFile As Folderitem = resourcesFolder.Child(imageName+"@3x.png")
  
  Var images() As Picture
  images.Add(picture.Open(image1xfile))
  images.Add(picture.Open(image2xfile))
  images.Add(picture.Open(image3xfile))
  
  Var w As Integer = images(0).Width
  Var h As Integer = images(0).Height
  
  Return New Picture(w, h, images)
  
End Function
5 Likes