CIContext
The Core Image context class provides an evaluation context for Core Image processing with Metal, OpenGL, or OpenCL.
Declaration
class CIContextMentioned in
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
CGColorSpacesee 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
Creating a Context for CPU-Based Rendering
Creating a Context for GPU-Based Rendering
Rendering Images
createCGImage(_:from:)createCGImage(_:from:format:colorSpace:)createCGImage(_:from:format:colorSpace:deferred:)render(_:toBitmap:rowBytes:bounds:format:colorSpace:)render(_:to:)render(_:to:bounds:colorSpace:)render(_:to:bounds:colorSpace:)render(_:to:commandBuffer:bounds:colorSpace:)
Drawing Images
Determining the Allowed Extents for Images Used by a Context
Managing Resources
Rendering Images for Data or File Export
tiffRepresentation(of:format:colorSpace:options:)jpegRepresentation(of:colorSpace:options:)pngRepresentation(of:format:colorSpace:options:)heifRepresentation(of:format:colorSpace:options:)heif10Representation(of:colorSpace:options:)openEXRRepresentation(of:options:)writeTIFFRepresentation(of:to:format:colorSpace:options:)writeJPEGRepresentation(of:to:colorSpace:options:)writePNGRepresentation(of:to:format:colorSpace:options:)writeHEIFRepresentation(of:to:format:colorSpace:options:)writeHEIF10Representation(of:to:colorSpace:options:)writeOpenEXRRepresentation(of:to:options:)CIImageRepresentationOption
Creating Depth Blur Filters
depthBlurEffectFilter(for:disparityImage:portraitEffectsMatte:hairSemanticSegmentation:glassesMatte:gainMap:orientation:options:)depthBlurEffectFilter(for:disparityImage:portraitEffectsMatte:hairSemanticSegmentation:orientation:options:)depthBlurEffectFilter(for:disparityImage:portraitEffectsMatte:orientation:options:)depthBlurEffectFilter(forImageData:options:)depthBlurEffectFilter(forImageURL:options:)
Constants
Customizing Render Destination
prepareRender(_:from:to:at:)startTask(toClear:)startTask(toRender:from:to:at:)startTask(toRender:to:)
Deprecated
init(cglContext:pixelFormat:colorSpace:options:)init(eaglContext:)init(eaglContext:options:)init(forOfflineGPUAtIndex:)init(forOfflineGPUAtIndex:colorSpace:options:sharedContext:)createCGLayer(with:info:)draw(_:at:from:)
Initializers
init(CGContext:options:)init(CGLContext:pixelFormat:colorSpace:options:)init(EAGLContext:)init(EAGLContext:options:)init(MTLCommandQueue:)init(MTLCommandQueue:options:)init(MTLDevice:)init(MTLDevice:options:)init(forOfflineGPUAt:)init(forOfflineGPUAt:colorSpace:options:sharedContext:)init(options:)
Instance Methods
calculateHDRStats(for:)calculateHDRStats(for:)calculateHDRStats(for:)calculateHDRStats(for:)createCGImage(_:from:format:colorSpace:deferred:calculateHDRStats:)