---
title: CIContext
framework: coreimage
role: symbol
role_heading: Class
path: coreimage/cicontext
---

# CIContext

The Core Image context class provides an evaluation context for Core Image processing with Metal, OpenGL, or OpenCL.

## Declaration

```swift
class CIContext
```

## Mentioned in

Processing an Image Using Built-in Filters

## Overview

Overview You use a CIContext instance to render a CIImage instance which represents a graph of image processing operations which are built using other Core Image classes, such as CIFilter, CIKernel, CIColor and CIImage. You can also use a CIContext with the CIDetector class to analyze images — for example, to detect faces or barcodes. Contexts support automatic color management by performing all processing operations in a working color space. This means that unless told otherwise: All input images are color matched from the input’s color space to the working space. All renders are color matched from the working space to the destination space. (For more information on CGColorSpace see CGColorSpace) CIContext and CIImage instances are immutable, so multiple threads can use the same CIContext instance to render CIImage instances. However, CIFilter instances are mutable and thus cannot be shared safely among threads. Each thread must take case not to access or modify a CIFilter instance while it is being used by another thread. The CIContext manages various internal state such as MTLCommandQueue and caches for compiled kernels and intermediate buffers.  For this reason it is not recommended to create many CIContext instances.  As a rule, it recommended that you create one CIContext instance for each view that renders CIImage or each background task.

## Topics

### Creating a Context Without Specifying a Destination

- [init()](coreimage/cicontext/init().md)

### Creating a Context for CPU-Based Rendering

- [init(cgContext:options:)](coreimage/cicontext/init(cgcontext:options:)-6p78w.md)

### Creating a Context for GPU-Based Rendering

- [init(mtlDevice:)](coreimage/cicontext/init(mtldevice:)-swey.md)
- [init(mtlDevice:options:)](coreimage/cicontext/init(mtldevice:options:)-26usb.md)
- [init(mtlCommandQueue:)](coreimage/cicontext/init(mtlcommandqueue:)-7dtqk.md)
- [init(mtlCommandQueue:options:)](coreimage/cicontext/init(mtlcommandqueue:options:)-6i3me.md)

### Rendering Images

- [createCGImage(_:from:)](coreimage/cicontext/createcgimage(_:from:).md)
- [createCGImage(_:from:format:colorSpace:)](coreimage/cicontext/createcgimage(_:from:format:colorspace:).md)
- [createCGImage(_:from:format:colorSpace:deferred:)](coreimage/cicontext/createcgimage(_:from:format:colorspace:deferred:).md)
- [render(_:toBitmap:rowBytes:bounds:format:colorSpace:)](coreimage/cicontext/render(_:tobitmap:rowbytes:bounds:format:colorspace:).md)
- [render(_:to:)](coreimage/cicontext/render(_:to:).md)
- [render(_:to:bounds:colorSpace:)](coreimage/cicontext/render(_:to:bounds:colorspace:)-2k8l2.md)
- [render(_:to:bounds:colorSpace:)](coreimage/cicontext/render(_:to:bounds:colorspace:)-54b9l.md)
- [render(_:to:commandBuffer:bounds:colorSpace:)](coreimage/cicontext/render(_:to:commandbuffer:bounds:colorspace:).md)

### Drawing Images

- [draw(_:in:from:)](coreimage/cicontext/draw(_:in:from:).md)

### Determining the Allowed Extents for Images Used by a Context

- [inputImageMaximumSize()](coreimage/cicontext/inputimagemaximumsize().md)
- [outputImageMaximumSize()](coreimage/cicontext/outputimagemaximumsize().md)

### Managing Resources

- [clearCaches()](coreimage/cicontext/clearcaches().md)
- [reclaimResources()](coreimage/cicontext/reclaimresources().md)
- [offlineGPUCount()](coreimage/cicontext/offlinegpucount().md)
- [workingColorSpace](coreimage/cicontext/workingcolorspace.md)
- [workingFormat](coreimage/cicontext/workingformat.md)

### Rendering Images for Data or File Export

- [tiffRepresentation(of:format:colorSpace:options:)](coreimage/cicontext/tiffrepresentation(of:format:colorspace:options:).md)
- [jpegRepresentation(of:colorSpace:options:)](coreimage/cicontext/jpegrepresentation(of:colorspace:options:).md)
- [pngRepresentation(of:format:colorSpace:options:)](coreimage/cicontext/pngrepresentation(of:format:colorspace:options:).md)
- [heifRepresentation(of:format:colorSpace:options:)](coreimage/cicontext/heifrepresentation(of:format:colorspace:options:).md)
- [heif10Representation(of:colorSpace:options:)](coreimage/cicontext/heif10representation(of:colorspace:options:).md)
- [openEXRRepresentation(of:options:)](coreimage/cicontext/openexrrepresentation(of:options:).md)
- [writeTIFFRepresentation(of:to:format:colorSpace:options:)](coreimage/cicontext/writetiffrepresentation(of:to:format:colorspace:options:).md)
- [writeJPEGRepresentation(of:to:colorSpace:options:)](coreimage/cicontext/writejpegrepresentation(of:to:colorspace:options:).md)
- [writePNGRepresentation(of:to:format:colorSpace:options:)](coreimage/cicontext/writepngrepresentation(of:to:format:colorspace:options:).md)
- [writeHEIFRepresentation(of:to:format:colorSpace:options:)](coreimage/cicontext/writeheifrepresentation(of:to:format:colorspace:options:).md)
- [writeHEIF10Representation(of:to:colorSpace:options:)](coreimage/cicontext/writeheif10representation(of:to:colorspace:options:).md)
- [writeOpenEXRRepresentation(of:to:options:)](coreimage/cicontext/writeopenexrrepresentation(of:to:options:).md)
- [CIImageRepresentationOption](coreimage/ciimagerepresentationoption.md)

### Creating Depth Blur Filters

- [depthBlurEffectFilter(for:disparityImage:portraitEffectsMatte:hairSemanticSegmentation:glassesMatte:gainMap:orientation:options:)](coreimage/cicontext/depthblureffectfilter(for:disparityimage:portraiteffectsmatte:hairsemanticsegmentation:glassesmatte:gainmap:orientation:options:).md)
- [depthBlurEffectFilter(for:disparityImage:portraitEffectsMatte:hairSemanticSegmentation:orientation:options:)](coreimage/cicontext/depthblureffectfilter(for:disparityimage:portraiteffectsmatte:hairsemanticsegmentation:orientation:options:).md)
- [depthBlurEffectFilter(for:disparityImage:portraitEffectsMatte:orientation:options:)](coreimage/cicontext/depthblureffectfilter(for:disparityimage:portraiteffectsmatte:orientation:options:).md)
- [depthBlurEffectFilter(forImageData:options:)](coreimage/cicontext/depthblureffectfilter(forimagedata:options:).md)
- [depthBlurEffectFilter(forImageURL:options:)](coreimage/cicontext/depthblureffectfilter(forimageurl:options:).md)

### Constants

- [CIContextOption](coreimage/cicontextoption.md)

### Customizing Render Destination

- [prepareRender(_:from:to:at:)](coreimage/cicontext/preparerender(_:from:to:at:).md)
- [startTask(toClear:)](coreimage/cicontext/starttask(toclear:).md)
- [startTask(toRender:from:to:at:)](coreimage/cicontext/starttask(torender:from:to:at:).md)
- [startTask(toRender:to:)](coreimage/cicontext/starttask(torender:to:).md)

### Deprecated

- [init(cglContext:pixelFormat:colorSpace:options:)](coreimage/cicontext/init(cglcontext:pixelformat:colorspace:options:)-6rp6d.md)
- [init(eaglContext:)](coreimage/cicontext/init(eaglcontext:)-8ajef.md)
- [init(eaglContext:options:)](coreimage/cicontext/init(eaglcontext:options:)-6uyqj.md)
- [init(forOfflineGPUAtIndex:)](coreimage/cicontext/init(forofflinegpuatindex:).md)
- [init(forOfflineGPUAtIndex:colorSpace:options:sharedContext:)](coreimage/cicontext/init(forofflinegpuatindex:colorspace:options:sharedcontext:).md)
- [createCGLayer(with:info:)](coreimage/cicontext/createcglayer(with:info:).md)
- [draw(_:at:from:)](coreimage/cicontext/draw(_:at:from:).md)

### Initializers

- [init(CGContext:options:)](coreimage/cicontext/init(cgcontext:options:)-1yzwi.md)
- [init(CGLContext:pixelFormat:colorSpace:options:)](coreimage/cicontext/init(cglcontext:pixelformat:colorspace:options:)-3t25h.md)
- [init(EAGLContext:)](coreimage/cicontext/init(eaglcontext:)-293h1.md)
- [init(EAGLContext:options:)](coreimage/cicontext/init(eaglcontext:options:)-2853a.md)
- [init(MTLCommandQueue:)](coreimage/cicontext/init(mtlcommandqueue:)-2pgxu.md)
- [init(MTLCommandQueue:options:)](coreimage/cicontext/init(mtlcommandqueue:options:)-q929.md)
- [init(MTLDevice:)](coreimage/cicontext/init(mtldevice:)-8ksdj.md)
- [init(MTLDevice:options:)](coreimage/cicontext/init(mtldevice:options:)-15xqo.md)
- [init(forOfflineGPUAt:)](coreimage/cicontext/init(forofflinegpuat:).md)
- [init(forOfflineGPUAt:colorSpace:options:sharedContext:)](coreimage/cicontext/init(forofflinegpuat:colorspace:options:sharedcontext:).md)
- [init(options:)](coreimage/cicontext/init(options:).md)

### Instance Methods

- [calculateHDRStats(for:)](coreimage/cicontext/calculatehdrstats(for:)-3ia7r.md)
- [calculateHDRStats(for:)](coreimage/cicontext/calculatehdrstats(for:)-6lwmz.md)
- [calculateHDRStats(for:)](coreimage/cicontext/calculatehdrstats(for:)-7bcki.md)
- [calculateHDRStats(for:)](coreimage/cicontext/calculatehdrstats(for:)-l1rj.md)
- [createCGImage(_:from:format:colorSpace:deferred:calculateHDRStats:)](coreimage/cicontext/createcgimage(_:from:format:colorspace:deferred:calculatehdrstats:).md)

### Default Implementations

- [CIContext Implementations](coreimage/cicontext/cicontext-implementations.md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Essentials

- [Processing an Image Using Built-in Filters](coreimage/processing-an-image-using-built-in-filters.md)
- [CIImage](coreimage/ciimage.md)
