Platforms to show: All Mac Windows Linux Cross-Platform

Back to CGImageDestinationMBS class.

CGImageDestinationMBS.CreateWithData(type as string, count as Integer = 1) as CGImageDestinationMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method CoreGraphics MBS MacCG Plugin 9.5 ✅ Yes ❌ No ❌ No ✅ Yes All
Creates an image destination that writes to a string.

type: The uniform type identifier (UTI) of the resulting image file. See Uniform Type Identifiers Overview for a list of system-declared and third-party UTIs.

count: The number of images (not including thumbnail images) that the image file will contain.

On error the function returns nil.

Available in Mac OS X version 10.4 and later.

CGImageDestinationMBS.CreateWithFile(file as folderitem, type as string, count as Integer = 1) as CGImageDestinationMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method CoreGraphics MBS MacCG Plugin 9.5 ✅ Yes ❌ No ❌ No ✅ Yes All
Creates an image destination that writes to a location specified by a folderitem.
Example
Dim p As Picture = LogoMBS(500)

// save as tiff

Dim image As CGImageMBS = CGImageMBS.CreateImage(p)
Dim file2 As FolderItem = SpecialFolder.Desktop.Child("test2.tif")
Dim dest As CGImageDestinationMBS = CGImageDestinationMBS.CreateWithFile(file2, "public.tiff", 1)

dest.AddImage(image, Nil)

If dest.Finalize Then
// MsgBox "Saved"
Else
MsgBox "Failed to save."
End If

file: The file to write to. If the file already exists, the data at this location is overwritten.

type: The UTI (uniform type identifier) of the resulting image file. See Uniform Type Identifiers Overview for a list of system-declared and third-party UTIs.

count: The number of images (not including thumbnail images) that the image file will contain.

On failure the function returns nil.

Available in Mac OS X version 10.4 and later.

CGImageDestinationMBS.CreateWithURL(url as string, type as string, count as Integer = 1) as CGImageDestinationMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method CoreGraphics MBS MacCG Plugin 9.5 ✅ Yes ❌ No ❌ No ✅ Yes All
Creates an image destination that writes to a location specified by a URL.

url: The URL to write to. If the URL already exists, the data at this location is overwritten.

type: The UTI (uniform type identifier) of the resulting image file. See Uniform Type Identifiers Overview for a list of system-declared and third-party UTIs.

count: The number of images (not including thumbnail images) that the image file will contain.

On error nil is returned.

Available in Mac OS X version 10.4 and later.

CGImageDestinationMBS.kCGImageDestinationBackgroundColor as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method CoreGraphics MBS MacCG Plugin 9.5 ✅ Yes ❌ No ❌ No ✅ Yes All
One of the constant for the image destination properties.

The desired background color to composite against when writing an image that has an alpha component to a destination format that does not support alpha. If present, the value associated with this key must be a CGColorRef data type without an alpha component of its own. If not present, and if a background color is needed, a white color is used.

Available in Mac OS X v10.4 and later.

CGImageDestinationMBS.kCGImageDestinationDateTime as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method CoreGraphics MBS MacCG Plugin 13.1 ✅ Yes ❌ No ❌ No ✅ Yes All
One of the constant for the image destination properties.

Updates the DateTime parameters of the image metadata. Only values present in the original image will updated. If present, the value should be a String or a Date. If String, the value must be in Exif DateTime or ISO 8601 DateTime format. This option is mutually exclusive with kCGImageDestinationMetadata.

CGImageDestinationMBS.kCGImageDestinationLossyCompressionQuality as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method CoreGraphics MBS MacCG Plugin 9.5 ✅ Yes ❌ No ❌ No ✅ Yes All
One of the constant for the image destination properties.

The desired compression quality to use when writing to an image destination. If present, the value associated with this key must be a double in the range 0.0 to 1.0. A value of 1.0 specifies to use lossless compression if destination format supports it. A value of 0.0 implies to use maximum compression.

Available in Mac OS X v10.4 and later.

Some examples using this method:

CGImageDestinationMBS.kCGImageDestinationMergeMetadata as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method CoreGraphics MBS MacCG Plugin 13.1 ✅ Yes ❌ No ❌ No ✅ Yes All
One of the constant for the image destination properties.
Example
// Change rotation in an image file

// files
dim dpath as folderitem = SpecialFolder.Desktop.Child("test.jpg")
dim opath as folderitem = dpath.parent.Child("output.jpg")

// open source
dim imageSource as new cgimagesourcembs(dpath)

// read image
dim img as cgimagembs = imageSource.createimageatindex(0)

// global properties
dim globalprop as dictionary = imageSource.properties
// per image properties
dim p as Dictionary = imageSource.PropertiesAtIndex(0)

dim imageDest as new CGImageDestinationMBS(opath,"public.jpeg",1)

'const orientation = 1 // top left
const orientation = 3 // bottom right

// set globals
imageDest.SetProperties(globalprop)

// now set new orientation
p.value(imageDest.kCGImageDestinationOrientation) = orientation
p.value(imageDest.kCGImageDestinationMergeMetadata) = true

// change tiff dictionary, if present
dim dTIFF as Dictionary = p.lookup(imageSource.kCGImagePropertyTIFFDictionary, nil)
if dTIFF <> nil then
dTIFF.value(imageSource.kCGImagePropertyTIFFOrientation) = orientation
end if

// change iptc dictionary, if present
dim dIPTC as Dictionary = p.lookup(imageSource.kCGImagePropertyIPTCDictionary, nil)
if dIPTC <> nil then
dIPTC.value(imageSource.kCGImagePropertyIPTCImageOrientation) = orientation
end if

// write out image
imageDest.AddImage(img,p)
call imageDest.Finalize

If true, The metadata will be copied from the source and merged with the tags specified in kCGImageDestinationMetadata. If a tag does not exist in the source, it will be added. If the tag exists in the source, it will be updated. A metadata tag can be removed by setting the tag's value to nil. If present, the value of this key is a Boolean. The default is False.

CGImageDestinationMBS.kCGImageDestinationMetadata as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method CoreGraphics MBS MacCG Plugin 13.1 ✅ Yes ❌ No ❌ No ✅ Yes All
One of the constant for the image destination properties.

Set the metadata tags for the image destination. If present, the value of this key is a CGImageMetadata. By default, all EXIF, IPTC, and XMP tags will be replaced. Use kCGImageDestinationMergeMetadata to merge the tags with the existing tags in the image source.

CGImageDestinationMBS.kCGImageDestinationOrientation as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method CoreGraphics MBS MacCG Plugin 13.1 ✅ Yes ❌ No ❌ No ✅ Yes All
One of the constant for the image destination properties.
Example
// Change rotation in an image file

// files
dim dpath as folderitem = SpecialFolder.Desktop.Child("test.jpg")
dim opath as folderitem = dpath.parent.Child("output.jpg")

// open source
dim imageSource as new cgimagesourcembs(dpath)

// read image
dim img as cgimagembs = imageSource.createimageatindex(0)

// global properties
dim globalprop as dictionary = imageSource.properties
// per image properties
dim p as Dictionary = imageSource.PropertiesAtIndex(0)

dim imageDest as new CGImageDestinationMBS(opath,"public.jpeg",1)

'const orientation = 1 // top left
const orientation = 3 // bottom right

// set globals
imageDest.SetProperties(globalprop)

// now set new orientation
p.value(imageDest.kCGImageDestinationOrientation) = orientation
p.value(imageDest.kCGImageDestinationMergeMetadata) = true

// change tiff dictionary, if present
dim dTIFF as Dictionary = p.lookup(imageSource.kCGImagePropertyTIFFDictionary, nil)
if dTIFF <> nil then
dTIFF.value(imageSource.kCGImagePropertyTIFFOrientation) = orientation
end if

// change iptc dictionary, if present
dim dIPTC as Dictionary = p.lookup(imageSource.kCGImagePropertyIPTCDictionary, nil)
if dIPTC <> nil then
dIPTC.value(imageSource.kCGImagePropertyIPTCImageOrientation) = orientation
end if

// write out image
imageDest.AddImage(img,p)
call imageDest.Finalize

Updates the orientation in the image metadata. The image data itself will not be rotated. If present, the value should be a Integer from 1 to 8. This option is mutually exclusive with kCGImageDestinationMetadata.

CGImageDestinationMBS.kCGImageMetadataShouldExcludeXMP as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method CoreGraphics MBS MacCG Plugin 13.1 ✅ Yes ❌ No ❌ No ✅ Yes All
One of the constant for the image destination properties.

XMP data will not be written to the destination. If used in conjunction with kCGImageDestinationMetadata, EXIF and/or IPTC tags will be preserved, but an XMP packet will not be written to the file. If present, the value for this key is a Boolean. The default is False.

CGImageDestinationMBS.TypeIdentifiers as string()

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method CoreGraphics MBS MacCG Plugin 9.5 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns an array of the uniform type identifiers (UTIs) that are supported for image destinations.
Example
dim s(-1) as string = CGImageDestinationMBS.TypeIdentifiers

MsgBox Join(s,EndOfLine)

// shows on Mac OS X 10.5:
//
// public.png
// public.jpeg
// com.compuserve.gif
// public.jpeg-2000
// public.tiff
// com.adobe.photoshop-image
// com.adobe.pdf
// com.microsoft.bmp
// com.apple.pict
// com.truevision.tga-image
// com.sgi.sgi-image
// com.ilm.openexr-image

Returns an array of the UTIs that are supported for image destinations. See Uniform Type Identifiers Overview for a list of system-declared and third-party UTIs that can be returned.

Available in Mac OS X version 10.4 and later.

The items on this page are in the following plugins: MBS MacCG Plugin.


The biggest plugin in space...