CVPixelBufferRef到NSImage
答
要将缓冲区转换为图像,需要先将缓冲区转换为CIImage
,然后才能将其转换为NSImage
。
let ciImage = CIImage(cvImageBuffer: pixelBuffer)
let context = CIContext(options: nil)
从这里你可以去这两个GCImage
和NSImage
:
let width = CVPixelBufferGetWidth(pixelBuffer)
let height = CVPixelBufferGetHeight(pixelBuffer)
let cgImage = context.createCGImage(ciImage, from: CGRect(x: 0, y: 0, width: width, height: height))
let nsImage = NSImage(cgImage: cgImage, size: CGSize(width: width, height: height))