init(cgImage:format:flags:)
Creates a new buffer with the contents of a Core Graphics image using the supplied image format.
Declaration
init(cgImage: CGImage, format: vImage_CGImageFormat, flags options: vImage.Options = .noFlags) throwsParameters
- cgImage:
The source image.
- format:
The desired image format.
- options:
The options to use when performing the operation.
Mentioned in
Discussion
This function converts the source Core Graphics image that the cgImage parameter specifies to the format that the format parameter describes.
For example, the following code converts a color image to grayscale and initializes the vImage buffer with the planar monochrome image data:
let format = vImage_CGImageFormat(
bitsPerComponent: 8,
bitsPerPixel: 8,
colorSpace: CGColorSpaceCreateDeviceGray(),
bitmapInfo: CGBitmapInfo(rawValue: CGImageAlphaInfo.none.rawValue))!
// `cgImage` is a color image.
let buffer = try vImage_Buffer(cgImage: cgImage,
format: format)