<!--
{
  "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

[`func CGImageSourceCreateWithURL(CFURL, CFDictionary?) -> CGImageSource?`](/documentation/ImageIO/CGImageSourceCreateWithURL(_:_:))

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

[`func CGImageSourceCreateWithData(CFData, CFDictionary?) -> CGImageSource?`](/documentation/ImageIO/CGImageSourceCreateWithData(_:_:))

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

[`func CGImageSourceCreateWithDataProvider(CGDataProvider, CFDictionary?) -> CGImageSource?`](/documentation/ImageIO/CGImageSourceCreateWithDataProvider(_:_:))

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

[`func CGImageSourceCreateIncremental(CFDictionary?) -> CGImageSource`](/documentation/ImageIO/CGImageSourceCreateIncremental(_:))

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

### Extracting Images From an Image Source

[`func CGImageSourceCreateImageAtIndex(CGImageSource, Int, CFDictionary?) -> CGImage?`](/documentation/ImageIO/CGImageSourceCreateImageAtIndex(_:_:_:))

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

[`func CGImageSourceCreateThumbnailAtIndex(CGImageSource, Int, CFDictionary?) -> CGImage?`](/documentation/ImageIO/CGImageSourceCreateThumbnailAtIndex(_:_:_:))

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

[`func CGImageSourceGetPrimaryImageIndex(CGImageSource) -> Int`](/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

[`func CGImageSourceGetTypeID() -> CFTypeID`](/documentation/ImageIO/CGImageSourceGetTypeID())

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

[`func CGImageSourceGetType(CGImageSource) -> CFString?`](/documentation/ImageIO/CGImageSourceGetType(_:))

Returns the uniform type identifier of the source container.

[`func CGImageSourceCopyTypeIdentifiers() -> CFArray`](/documentation/ImageIO/CGImageSourceCopyTypeIdentifiers())

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

[`func CGImageSourceGetCount(CGImageSource) -> Int`](/documentation/ImageIO/CGImageSourceGetCount(_:))

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

[`func CGImageSourceCopyProperties(CGImageSource, CFDictionary?) -> CFDictionary?`](/documentation/ImageIO/CGImageSourceCopyProperties(_:_:))

Returns the properties of the image source.

[`func CGImageSourceCopyPropertiesAtIndex(CGImageSource, Int, CFDictionary?) -> CFDictionary?`](/documentation/ImageIO/CGImageSourceCopyPropertiesAtIndex(_:_:_:))

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

[`func CGImageSourceCopyAuxiliaryDataInfoAtIndex(CGImageSource, Int, CFString) -> CFDictionary?`](/documentation/ImageIO/CGImageSourceCopyAuxiliaryDataInfoAtIndex(_:_:_:))

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

### Updating an Incremental Image

[`func CGImageSourceUpdateData(CGImageSource, CFData, Bool)`](/documentation/ImageIO/CGImageSourceUpdateData(_:_:_:))

Updates the data in an incremental image source.

[`func CGImageSourceUpdateDataProvider(CGImageSource, CGDataProvider, Bool)`](/documentation/ImageIO/CGImageSourceUpdateDataProvider(_:_:_:))

Updates an incremental image source with a new data provider.

### Getting the Image Status

[`func CGImageSourceGetStatus(CGImageSource) -> CGImageSourceStatus`](/documentation/ImageIO/CGImageSourceGetStatus(_:))

Return the status of an image source.

[`func CGImageSourceGetStatusAtIndex(CGImageSource, Int) -> CGImageSourceStatus`](/documentation/ImageIO/CGImageSourceGetStatusAtIndex(_:_:))

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

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

The set of status values for images and image sources.

### Specifying the Read Options

[`let kCGImageSourceTypeIdentifierHint: CFString`](/documentation/ImageIO/kCGImageSourceTypeIdentifierHint)

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

[`let kCGImageSourceShouldAllowFloat: CFString`](/documentation/ImageIO/kCGImageSourceShouldAllowFloat)

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

[`let kCGImageSourceShouldCache: CFString`](/documentation/ImageIO/kCGImageSourceShouldCache)

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

[`let kCGImageSourceShouldCacheImmediately: CFString`](/documentation/ImageIO/kCGImageSourceShouldCacheImmediately)

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

[`let kCGImageSourceCreateThumbnailFromImageIfAbsent: CFString`](/documentation/ImageIO/kCGImageSourceCreateThumbnailFromImageIfAbsent)

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

[`let kCGImageSourceCreateThumbnailFromImageAlways: CFString`](/documentation/ImageIO/kCGImageSourceCreateThumbnailFromImageAlways)

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

[`let kCGImageSourceThumbnailMaxPixelSize: CFString`](/documentation/ImageIO/kCGImageSourceThumbnailMaxPixelSize)

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

[`let kCGImageSourceCreateThumbnailWithTransform: CFString`](/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.

[`let kCGImageSourceSubsampleFactor: CFString`](/documentation/ImageIO/kCGImageSourceSubsampleFactor)

The factor by which to scale down any returned images.

[`let kCGImageSourceAllowableTypes: CFString`](/documentation/ImageIO/kCGImageSourceAllowableTypes)

Option key for restricting which image formats can be decoded.

## 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)