Function

vImageBuffer_InitWithCGImage(_:_:_:_:_:)

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

Declaration

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

Parameters

buf

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

format

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

backgroundColor

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

image

A CGImage instance to be used as the source.

flags

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

kvImageNoFlags

Default behavior.

kvImageNoAllocate

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

kvImagePrintDiagnosticsToConsole

Prints a debug message if the operation fails.

kvImageDoNotTile

Disables internal multithreading.

Return Value

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

Discussion

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.