Topics   All   MacOS (Only)   Windows (Only)   Linux (Only, Not)   iOS (Only, Not)  
Components   Crossplatform Mac & Win   Server   Client   Old   Guides   Examples
New in version: 9.0   9.1   9.2   9.3   9.4   9.5   10.0   10.1   10.2   10.3    Statistic  


Returns the image associated with the specified index in an image source.

Component Version macOS Windows Server FileMaker Cloud FileMaker iOS SDK
CGImageSource 3.4 Yes No Yes, macOS only No Yes
MBS( "CGImageSource.ImageAtIndex"; Ref; Index { ; ImageType; Filename } )   More


Parameter Description Example value
Ref The image source reference number returned by CGImageSource.CreateWithData, CGImageSource.CreateWithPath or CGImageSource.CreateWithURL $ref
Index The index of the image to query. -1 for global properties. Else a number from 0 to CGImageSource.Count-1. 0
ImageType Optional
The type of image to return. Either JPEG, PNG, GIF or BMP. Default is JPEG.
Filename Optional
The filename to use for the picture. Default is "image" with the extension matching the image type.


Returns image or error message.


Returns the image associated with the specified index in an image source.
This function can be used to query previews of various image formats including RAW images. (everything Preview app can also open)


Convert image from one container and output to other:

Set Variable [ $img ; Value: MBS( "CGImageSource.CreateWithData"; test::input ) ]
Set Field [ test::output ; MBS( "CGImageSource.ImageAtIndex"; $img; 0; "PNG") ]
Set Variable [ $r ; Value: MBS( "CGImageSource.Release"; $img ) ]

Read HEIC image:

Set Variable [ $path ; Value: "/Users/cs/Desktop/IMG_3552.HEIC" ]
Set Variable [ $ImageSource ; Value: MBS( "CGImageSource.CreateWithPath"; $path) ]
If [ MBS("IsError") = 0 ]
    # you can get metadata as JSON to check later...
    Set Variable [ $$MetaData ; Value: MBS( "CGImageSource.Properties"; $ImageSource ) ]
    Set Variable [ $$ImageMetaData ; Value: MBS( "CGImageSource.Properties"; $ImageSource; 0 ) ]
    # get image to show
    Set Variable [ $image ; Value: MBS( "CGImageSource.ImageAtIndex"; $ImageSource; 0; "PNG"; "image.png") ]
    If [ MBS("IsError") = 0 ]
        Set Field [ Untitled::image ; $image ]
    End If
    Set Variable [ $r ; Value: MBS( "CGImageSource.Release"; $ImageSource ) ]
End If

See also

Blog Entries

Created 18th August 2014, last changed 20th August 2019

CGImageSource.HasProperty   -   CGImageSource.Keys

Feedback: Report problem or ask question.

MBS Xojo Plugins