<!--
{
  "availability" : [
    "iOS: 4.0.0 -",
    "iPadOS: 4.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.8.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "ImageIO",
  "identifier" : "/documentation/ImageIO/CGImageDestination",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Image I/O"
    ],
    "preciseIdentifier" : "c:@T@CGImageDestinationRef"
  },
  "title" : "CGImageDestination"
}
-->

# CGImageDestination

An opaque type that you use to write image data to a URL, data object, or data consumer.

```
class CGImageDestination
```

## Overview

A [`CGImageDestination`](/documentation/ImageIO/CGImageDestination) object provides an abstract interface for saving image data. Use an image destination to represent a single image, or multiple images packaged together. For example, you might create an image that also contains a thumbnail. You can also use the image destination to add metadata to your images.

An image destination outputs data to a URL, a `CFData` object, or a <doc://com.apple.documentation/documentation/CoreGraphics/CGDataConsumer> object, which you specify at creation time. After you create the image destination, add the image data and properties. When you are done, call [`CGImageDestinationFinalize(_:)`](/documentation/ImageIO/CGImageDestinationFinalize(_:)) to finalize the image data and write it to the output location.

For more information, see [Image I/O Programming Guide](https://developer.apple.com/library/archive/documentation/GraphicsImaging/Conceptual/ImageIOGuide/imageio_intro/ikpg_intro.html#//apple_ref/doc/uid/TP40005462).

## Topics

### Creating an Image Destination

[`CGImageDestinationCreateWithURL(_:_:_:_:)`](/documentation/ImageIO/CGImageDestinationCreateWithURL(_:_:_:_:))

Creates an image destination that writes image data to the specified URL.

[`CGImageDestinationCreateWithData(_:_:_:_:)`](/documentation/ImageIO/CGImageDestinationCreateWithData(_:_:_:_:))

Creates an image destination that writes to a Core Foundation mutable data object.

[`CGImageDestinationCreateWithDataConsumer(_:_:_:_:)`](/documentation/ImageIO/CGImageDestinationCreateWithDataConsumer(_:_:_:_:))

Creates an image destination that writes to the specified data consumer.

### Adding Images to the Destination

[`CGImageDestinationAddImage(_:_:_:)`](/documentation/ImageIO/CGImageDestinationAddImage(_:_:_:))

Adds an image to an image destination.

[`CGImageDestinationAddImageFromSource(_:_:_:_:)`](/documentation/ImageIO/CGImageDestinationAddImageFromSource(_:_:_:_:))

Adds an image from an image source to an image destination.

### Adding Metadata to the Image

[`CGImageDestinationSetProperties(_:_:)`](/documentation/ImageIO/CGImageDestinationSetProperties(_:_:))

Applies one or more properties to all images in an image destination.

[`CGImageDestinationAddAuxiliaryDataInfo(_:_:_:)`](/documentation/ImageIO/CGImageDestinationAddAuxiliaryDataInfo(_:_:_:))

Sets the auxiliary data, such as mattes and depth information, that accompany the image.

### Finalizing the Image Data

[`CGImageDestinationFinalize(_:)`](/documentation/ImageIO/CGImageDestinationFinalize(_:))

Writes image data and properties to the data, URL, or data consumer associated with the image destination.

### Getting the Image Types

[`CGImageDestinationCopyTypeIdentifiers()`](/documentation/ImageIO/CGImageDestinationCopyTypeIdentifiers())

Returns an array of the uniform type identifiers that are supported for image destinations.

[`CGImageDestinationGetTypeID()`](/documentation/ImageIO/CGImageDestinationGetTypeID())

Returns the unique type identifier of an image destination opaque type.

### Configuring the Image Behaviors

[`kCGImageDestinationLossyCompressionQuality`](/documentation/ImageIO/kCGImageDestinationLossyCompressionQuality)

The desired compression quality to use when writing the image data.

[`kCGImageDestinationBackgroundColor`](/documentation/ImageIO/kCGImageDestinationBackgroundColor)

The background color to use when the image has an alpha component, but the destination format doesn’t support alpha.

[`kCGImageDestinationDateTime`](/documentation/ImageIO/kCGImageDestinationDateTime)

The date and time information to associate with the image.

[`kCGImageDestinationEmbedThumbnail`](/documentation/ImageIO/kCGImageDestinationEmbedThumbnail)

A Boolean value that indicates whether to embed a thumbnail for JPEG and HEIF images.

[`kCGImageDestinationImageMaxPixelSize`](/documentation/ImageIO/kCGImageDestinationImageMaxPixelSize)

The maximum width and height of the image, in pixels.

[`kCGImageDestinationMetadata`](/documentation/ImageIO/kCGImageDestinationMetadata)

The metadata tags to include with the image.

[`kCGImageDestinationMergeMetadata`](/documentation/ImageIO/kCGImageDestinationMergeMetadata)

A Boolean value that indicates whether to merge new metadata with the image’s existing metadata.

[`kCGImageDestinationOptimizeColorForSharing`](/documentation/ImageIO/kCGImageDestinationOptimizeColorForSharing)

A Boolean value that indicates whether to create the image using a colorspace.

[`kCGImageDestinationOrientation`](/documentation/ImageIO/kCGImageDestinationOrientation)

The orientation of the image, specified as an EXIF value in the range 1 to 8.

[`kCGImageDestinationPreserveGainMap`](/documentation/ImageIO/kCGImageDestinationPreserveGainMap)

A Boolean value that indicates whether to include a HEIF-embedded gain map in the image data.

[`kCGImageMetadataShouldExcludeGPS`](/documentation/ImageIO/kCGImageMetadataShouldExcludeGPS)

A Boolean value that indicates whether to exclude GPS metadata from EXIF data or the corresponding XMP tags.

[`kCGImageMetadataShouldExcludeXMP`](/documentation/ImageIO/kCGImageMetadataShouldExcludeXMP)

A Boolean value that indicates whether to exclude XMP data from the destination.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)