我该如何将CVPixelBufferRef转换为NSImage或CGImageRef?我需要能够在Core Animation层中显示像素缓冲区的内容。
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))