CVPixelBufferRef转换为NSImage

8
我该如何将CVPixelBufferRef转换为NSImage或CGImageRef?我需要能够在Core Animation层中显示像素缓冲区的内容。
1个回答

1
将缓冲区转换为图像,您需要先将缓冲区转换为 CIImage,然后再将其转换为 NSImage
let ciImage = CIImage(cvImageBuffer: pixelBuffer)

let context = CIContext(options: nil)

从这里您可以访问GCImageNSImage
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))

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接