Initializes a vImage buffer with the contents of a Core Graphics image.


func vImageBuffer_InitWithCGImage(_ buf: UnsafeMutablePointer<vImage_Buffer>, _ format: UnsafeMutablePointer<vImage_CGImageFormat>, _ backgroundColor: UnsafePointer<CGFloat>!, _ image: CGImage, _ flags: vImage_Flags) -> vImage_Error



A valid vImage_Buffer structure. The fields of the structure buf are updated to point to a vImage buffer representation of the image.


A valid vImage_CGImageFormat structure specifying the desired image format associated with the output buf. If format->colorspace is NULL, sRGB is used.


If the image encodes an alpha or mask, and the output format doesn't have alpha, the result is flattened against a background color.


A CGImage instance to be used as the source.


The options to use when performing this operation. The following flags are supported:


Default behavior.


Uses the passed-in buf->data and buf->rowBytes values without modification, allowing you to allocate your own buffer to hold the result.


Prints a debug message if the operation fails.


Disables internal multithreading.

Return Value

kvImageNoError; otherwise, one of the error codes described in Data Types and Constants.


This function is a convenience method to help you initialize a vImage_Buffer structure with an image from a CGImage instance. It initializes the vImage buffer by copying the image's pixel data to the buffer's memory. By default, a newly allocated piece of memory is used to hold the image.

You're responsible for releasing the memory that buf->data points to back to the system using free().

The CGImage instance may have other associated metadata, such as camera orientation, that may require further processing downstream. vImage does 1:1 pixel conversions from the raw image source.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software