<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreGraphics",
  "identifier" : "/documentation/CoreGraphics/CGImage",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Core Graphics"
    ],
    "preciseIdentifier" : "c:@T@CGImageRef"
  },
  "title" : "CGImage"
}
-->

# CGImage

A bitmap image or image mask.

```
class CGImage
```

## Overview

A bitmap image is a rectangular array of pixels, each of which represents a single sample or data point from a source image.

## Topics

### Creating images

[`init?(width: Int, height: Int, bitsPerComponent: Int, bitsPerPixel: Int, bytesPerRow: Int, space: CGColorSpace, bitmapInfo: CGBitmapInfo, provider: CGDataProvider, decode: UnsafePointer<CGFloat>?, shouldInterpolate: Bool, intent: CGColorRenderingIntent)`](/documentation/CoreGraphics/CGImage/init(width:height:bitsPerComponent:bitsPerPixel:bytesPerRow:space:bitmapInfo:provider:decode:shouldInterpolate:intent:))

Creates a bitmap image from data supplied by a data provider.

[`init?(jpegDataProviderSource: CGDataProvider, decode: UnsafePointer<CGFloat>?, shouldInterpolate: Bool, intent: CGColorRenderingIntent)`](/documentation/CoreGraphics/CGImage/init(jpegDataProviderSource:decode:shouldInterpolate:intent:))

Creates a bitmap image using JPEG-encoded data supplied by a data provider.

[`init?(pngDataProviderSource: CGDataProvider, decode: UnsafePointer<CGFloat>?, shouldInterpolate: Bool, intent: CGColorRenderingIntent)`](/documentation/CoreGraphics/CGImage/init(pngDataProviderSource:decode:shouldInterpolate:intent:))

Creates a bitmap image using PNG-encoded data supplied by a data provider.

[`init?(headroom: Float, width: Int, height: Int, bitsPerComponent: Int, bitsPerPixel: Int, bytesPerRow: Int, space: CGColorSpace, bitmapInfo: CGBitmapInfo, provider: CGDataProvider, decode: UnsafePointer<CGFloat>?, shouldInterpolate: Bool, intent: CGColorRenderingIntent)`](/documentation/CoreGraphics/CGImage/init(headroom:width:height:bitsPerComponent:bitsPerPixel:bytesPerRow:space:bitmapInfo:provider:decode:shouldInterpolate:intent:))

### Retaining and releasing images

[`extern CGImageRefCGImageRetain(CGImageRef image);`](/documentation/CoreGraphics/CGImageRetain)

Increments the retain count of a bitmap image.

[`extern void CGImageRelease(CGImageRef image);`](/documentation/CoreGraphics/CGImageRelease)

Decrements the retain count of a bitmap image.

### Examining an image

[`var isMask: Bool`](/documentation/CoreGraphics/CGImage/isMask)

Returns whether a bitmap image is an image mask.

[`var width: Int`](/documentation/CoreGraphics/CGImage/width)

Returns the width of a bitmap image, in pixels.

[`var height: Int`](/documentation/CoreGraphics/CGImage/height)

Returns the height of a bitmap image.

[`var bitsPerComponent: Int`](/documentation/CoreGraphics/CGImage/bitsPerComponent)

Returns the number of bits allocated for a single color component of a bitmap image.

[`var bitsPerPixel: Int`](/documentation/CoreGraphics/CGImage/bitsPerPixel)

Returns the number of bits allocated for a single pixel in a bitmap image.

[`var bytesPerRow: Int`](/documentation/CoreGraphics/CGImage/bytesPerRow)

Returns the number of bytes allocated for a single row of a bitmap image.

[`var colorSpace: CGColorSpace?`](/documentation/CoreGraphics/CGImage/colorSpace)

Return the color space for a bitmap image.

[`var alphaInfo: CGImageAlphaInfo`](/documentation/CoreGraphics/CGImage/alphaInfo)

Returns the alpha channel information for a bitmap image.

[`enum CGImageAlphaInfo`](/documentation/CoreGraphics/CGImageAlphaInfo)

Storage options for alpha component data.

[`var dataProvider: CGDataProvider?`](/documentation/CoreGraphics/CGImage/dataProvider)

Returns the data provider for a bitmap image or image mask.

[`var decode: UnsafePointer<CGFloat>?`](/documentation/CoreGraphics/CGImage/decode)

Returns the decode array for a bitmap image.

[`var shouldInterpolate: Bool`](/documentation/CoreGraphics/CGImage/shouldInterpolate)

Returns the interpolation setting for a bitmap image.

[`var renderingIntent: CGColorRenderingIntent`](/documentation/CoreGraphics/CGImage/renderingIntent)

Returns the rendering intent setting for a bitmap image.

[`var bitmapInfo: CGBitmapInfo`](/documentation/CoreGraphics/CGImage/bitmapInfo)

Returns the bitmap information for a bitmap image.

[`struct CGBitmapInfo`](/documentation/CoreGraphics/CGBitmapInfo)

Component information for a bitmap image.

[`var utType: CFString?`](/documentation/CoreGraphics/CGImage/utType)

The Universal Type Identifier for the image.

### Copying an image

[`func copy() -> CGImage?`](/documentation/CoreGraphics/CGImage/copy())

Creates a copy of a bitmap image.

[`func copy(colorSpace: CGColorSpace) -> CGImage?`](/documentation/CoreGraphics/CGImage/copy(colorSpace:))

Creates a copy of a bitmap image, replacing its colorspace.

### Creating images by modifying an image

[`func cropping(to: CGRect) -> CGImage?`](/documentation/CoreGraphics/CGImage/cropping(to:))

Creates a bitmap image using the data contained within a subregion of an existing bitmap image.

[`func masking(CGImage) -> CGImage?`](/documentation/CoreGraphics/CGImage/masking(_:))

Creates a bitmap image from an existing image and an image mask.

[`func copy(maskingColorComponents: [CGFloat]) -> CGImage?`](/documentation/CoreGraphics/CGImage/copy(maskingColorComponents:))

### Creating image masks

[`init?(maskWidth: Int, height: Int, bitsPerComponent: Int, bitsPerPixel: Int, bytesPerRow: Int, provider: CGDataProvider, decode: UnsafePointer<CGFloat>?, shouldInterpolate: Bool)`](/documentation/CoreGraphics/CGImage/init(maskWidth:height:bitsPerComponent:bitsPerPixel:bytesPerRow:provider:decode:shouldInterpolate:))

Creates a bitmap image mask from data supplied by a data provider.

[`extern CGImageRefCGImageCreateWithMaskingColors(CGImageRef image, const CGFloat *components);`](/documentation/CoreGraphics/CGImageCreateWithMaskingColors)

Creates a bitmap image by masking an existing bitmap image with the provided color values.

### Adopting high dynamic range (HDR)

[Enhancing high dynamic range image rendering](/documentation/CoreGraphics/adopting-advancements-in-hdr-image-rendering)

Improve your app’s High Dynamic Range (HDR) image support with metadata.

[`var contentHeadroom: Float`](/documentation/CoreGraphics/CGImage/contentHeadroom)

[`var calculatedContentHeadroom: Float`](/documentation/CoreGraphics/CGImage/calculatedContentHeadroom)

[`var contentAverageLightLevel: Float`](/documentation/CoreGraphics/CGImage/contentAverageLightLevel)

[`var calculatedContentAverageLightLevel: Float`](/documentation/CoreGraphics/CGImage/calculatedContentAverageLightLevel)

[`func copy(contentAverageLightLevel: Float) -> CGImage?`](/documentation/CoreGraphics/CGImage/copy(contentAverageLightLevel:))

[`func copyWithCalculatedHDRStats() -> CGImage?`](/documentation/CoreGraphics/CGImage/copyWithCalculatedHDRStats())

### Constants

[`enum CGImageAlphaInfo`](/documentation/CoreGraphics/CGImageAlphaInfo)

Storage options for alpha component data.

[`struct CGBitmapInfo`](/documentation/CoreGraphics/CGBitmapInfo)

Component information for a bitmap image.

[Host Endian Bitmap Formats](/documentation/CoreGraphics/host-endian-bitmap-formats)

Bit-depth constants for image bitmaps in host-endian byte order.

### Working with Core Foundation types

[`class var typeID: CFTypeID`](/documentation/CoreGraphics/CGImage/typeID)

Returns the type identifier for CGImage objects.

### Instance properties

[`var byteOrderInfo: CGImageByteOrderInfo`](/documentation/CoreGraphics/CGImage/byteOrderInfo)

[`var containsImageSpecificToneMappingMetadata: Bool`](/documentation/CoreGraphics/CGImage/containsImageSpecificToneMappingMetadata)

[`var contentHeadroom: Float`](/documentation/CoreGraphics/CGImage/contentHeadroom)

[`var pixelFormatInfo: CGImagePixelFormatInfo`](/documentation/CoreGraphics/CGImage/pixelFormatInfo)

[`var shouldToneMap: Bool`](/documentation/CoreGraphics/CGImage/shouldToneMap)

## See Also

  [Quartz 2D Programming Guide](https://developer.apple.com/library/archive/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/Introduction/Introduction.html#//apple_ref/doc/uid/TP30001066)

## Relationships

### Conforms To

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

[`AttachableAsImage`](/documentation/Testing/AttachableAsImage)

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

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

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

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

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

---

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)