<!--
{
  "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/CGImageSource",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Image I/O"
    ],
    "preciseIdentifier" : "c:@T@CGImageSourceRef"
  },
  "title" : "CGImageSource"
}
-->

# CGImageSource

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

```
class CGImageSource
```

## Overview

Use a [`CGImageSource`](/documentation/ImageIO/CGImageSource) type to read data efficiently for most image file formats. The image source object manages the data buffers needed to load the image data and performs any operations on that data to turn it into a usable image. For example, it decompresses data stored in a compressed format. You can also use an image source to fetch or create thumbnail images and access metadata stored with the image.

Create an image source object from a <doc://com.apple.documentation/documentation/CoreFoundation/CFURL>, <doc://com.apple.documentation/documentation/CoreFoundation/CFData>, or <doc://com.apple.documentation/documentation/CoreGraphics/CGDataProvider> data type. The image source object reads data from the specified type and extracts the image information for you.

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 Source

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

Creates an image source that reads from a location specified by a URL.

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

Creates an image source that reads from a Core Foundation data object.

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

Creates an image source that reads data from the specified data provider.

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

Creates an empty image source that you can use to accumulate incremental image data.

### Extracting Images From an Image Source

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

Creates an image object from the data at the specified index in an image source.

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

Creates a thumbnail version of the image at the specified index in an image source.

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

Returns the index of the primary image for an High Efficiency Image File Format (HEIF) image.

### Getting Information From an Image Source

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

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

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

Returns the uniform type identifier of the source container.

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

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

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

Returns the number of images (not including thumbnails) in the image source.

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

Returns the properties of the image source.

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

Returns the properties of the image at a specified location in an image source.

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

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

### Updating an Incremental Image

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

Updates the data in an incremental image source.

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

Updates an incremental image source with a new data provider.

### Getting the Image Status

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

Return the status of an image source.

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

Returns the current status of an image at the specified location in the image source.

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

The set of status values for images and image sources.

### Specifying the Read Options

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

The uniform type identifier that represents your best guess for the image’s type.

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

A Boolean that indicates whether to use floating-point values in returned images.

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

A Boolean value that indicates whether to cache the decoded image.

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

A Boolean value that indicates whether image decoding and caching happens at image creation time.

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

A Boolean value that indicates whether to create a thumbnail image automatically if the data source doesn’t contain one.

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

A Boolean value that indicates whether to always create a thumbnail image.

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

The maximum width and height of a thumbnail image, specified in pixels.

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

A Boolean value that indicates whether to rotate and scale the thumbnail image to match the image’s orientation and aspect ratio.

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

The factor by which to scale down any returned images.

## Relationships

### Conforms To

[`Hashable`](/documentation/Swift/Hashable)

[`Equatable`](/documentation/Swift/Equatable)

---

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)