Picture.ImageAt

From Xojo Documentation

Read-Only Property (As Picture )
PictureValue = aPicture.ImageAt(Index As Integer)

Supported for all project types and targets.

Returns the image in the picture specified by the passed Index (0-based).

Notes

The individual pictures aren't necessarily stored/returned in ascending scalefactor order. Do not rely on a particular order for the pictures.

Sample Code

This example gets the image referenced by the passed index and displays it in the ImageWell.

Var pic As Picture
Var f As FolderItem
f = FolderItem.ShowOpenFileDialog("image/jpeg")
If f <> Nil Then
pic = Picture.Open(f)
ImageWell1.Image = pic.ImageAt(0)
End If

If you have an Image Set with multiple images for HiDPI and want to split out each of the pictures it contains, you can do so like this:

Var g As Graphics
Var p, pics() As Picture

// Break the Image into its component pictures
// Also copy the horizontal/vertical resolution and scale factors
// so that the pictures draw properly when used later.
For i As Integer = 0 To MyImageSet.ImageCount - 1
p = New Picture(MyImageSet.ImageAt(i).Width, ImageAt(i).Height)
p.HorizontalResolution = MyImageSet.IndexedImage(i).HorizontalResolution
p.VerticalResolution = MyImageSet.IndexedImage(i).VerticalResolution
pics.Add(p)
g = p.Graphics
g.ScaleX = p.HorizontalResolution / 72
g.ScaleY = p.VerticalResolution / 72
g.DrawPicture(MyImageSet.ImageAt(i), 0, 0)
Next

If you later modify the pictures in the array and want to recreate it as an image, you can do so using the constructor like this:

// Recreate the image from the component pictures
p = New Picture(MyImageSet.Width, MyImageSet.Height, pics)