withCVPixelBuffer(readOnly:body:)
Calls the given closure with a locked 32-bit BGRA Core Video Pixel Buffer.
Declaration
func withCVPixelBuffer(readOnly: Bool, body: (CVPixelBuffer) -> Void)Parameters
- readOnly:
A Boolean value that specifies whether the function locks the Cvpixelbuffer with the Readonly flag. If the closure doesn’t modify the data, set this parameter to
true. - body:
A closure with a Cvpixelbuffer parameter that points to the underlying pixel buffer image data.
Discussion
Use this function to pass a vImage pixel buffer to other frameworks. For example, the following code creates a Core Image CIImage instance from a CVPixelBuffer that shares its underlying storage with a pixel buffer:
let src = vImage.PixelBuffer<vImage.Interleaved8x4>(
size: vImage.Size(width: 64, height: 64))
src.withCVPixelBuffer(readOnly: false) { cvPixelBuffer in
let ciImage = CIImage(cvImageBuffer: cvPixelBuffer)
// Core Image workflow using `ciImage`
}