Topics   All   MacOS (Only)   Windows (Only)   Linux (Only, Not)   iOS (Only, Not)  
Components   Crossplatform Mac & Win   Server   Client   Old   Deprecated   Guides   Examples   Videos
New in version: 11.2   11.3   11.4   11.5   12.0   12.1   12.2   12.3   12.4   12.5    Statistic    FMM    Blog  

Container.ReadImage

Reads and convert image.

Component Version macOS Windows Linux Server iOS SDK
Container 8.4 ✅ Yes ❌ No ❌ No ✅ Yes, on macOS ✅ Yes
MBS( "Container.ReadImage"; Container { ; ImageType; FileName } )   More

Parameters

Parameter Description Example Flags
Container The container field or value to inspect. MyTable::MyContainerField
ImageType The type of image to return.
Either JPEG, PNG, GIF or BMP. Default is JPEG.
"JPEG" Optional
FileName The filename to use for the picture.
Default is "image" with the extension matching the image type.
"test.jpg" Optional

Result

Returns image container or error.

Description

Reads and convert image.
This function is useful to read all the image formats supported by Apple's frameworks and convert them to a common format like JPEG or PNG.
Use this function to convert old PICT images in containers.
Works as well for HEIC and HEIF images.

Examples

Convert PICT to PNG:

Set Field [ Test::output ; MBS("Container.ReadImage"; Test::OldImage; "PNG"; "image.png") ]

Read file from disk and read as image:

Set Field [ Batch Emailer::Inline Graphics ; MBS("Container.ReadImage"; MBS("Container.ReadFile"; "/Users/cs/Desktop/test.heic")) ]

Read HEIC file:

Set Variable [ $path ; Value: "/Users/cs/Desktop/IMG_3552.HEIC" ]
Set Variable [ $container ; Value: MBS( "Container.ReadFile"; $path) ]
If [ MBS("IsError") = 0 ]
    Set Variable [ $image ; Value: MBS( "Container.ReadImage"; $container; "PNG"; "image.png") ]
    If [ MBS("IsError") = 0 ]
        Set Field [ Untitled::image ; $image ]
    End If
End If

Convert a PSD or HEIF image to PNG:

Set Field [ Contacts::Output ; MBS( "Container.ReadImage"; Contacts::Input; "PNG"; "test.png" ) ]

Insert picture from device and then convert HEIF

# let user take a picture
Insert from Device [ Contacts::Photo Container ; Type: Camera ; Camera: Back; Resolution: Full ]
#
# check filename
Set Variable [ $name ; Value: GetAsText(Contacts::Photo Container) ]
Set Variable [ $extension ; Value: Right ( $name ; 5 ) ]
If [ $extension = ".heif" or $extension = ".heic" ]
    # we got a HEIF image
    #
    # get new file name
    Set Variable [ $name ; Value: Substitute($name; ".heif"; ".png") ]
    Set Variable [ $name ; Value: Substitute($name; ".heic"; ".png") ]
    #
    # now convert to PNG
    Set Variable [ $image ; Value: MBS( "Container.ReadImage"; Contacts::Photo Container; "PNG"; $name ) ]
    If [ MBS("IsError") = 0 ]
        # save on success to container
        Set Field [ Contacts::Photo Container ; $name ]
    Else
        Show Custom Dialog [ "Read Image Failed?" ; $image ]
    End If
End If

See also

Release notes

Blog Entries

Created 29th July 2018, last changed 17th June 2021


Container.ReadFile - Container.ReadImageFile

Feedback: Report problem or ask question.


Start Chat