Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macos CVPixelBufferRef到NSImage_Macos_Cocoa_Osx Lion_Nsimage - Fatal编程技术网

Macos CVPixelBufferRef到NSImage

Macos CVPixelBufferRef到NSImage,macos,cocoa,osx-lion,nsimage,Macos,Cocoa,Osx Lion,Nsimage,如何将CVPixelBufferRef转换为NSImage或CGImageRef?我需要能够在核心动画层中显示像素缓冲区的内容。要将缓冲区转换为图像,首先需要将缓冲区转换为CIImage,然后可以将其转换为NSImage let ciImage = CIImage(cvImageBuffer: pixelBuffer) let context = CIContext(options: nil) 从这里可以转到GCImage和NSImage: let width = CVPixelBuffer

如何将CVPixelBufferRef转换为NSImage或CGImageRef?我需要能够在核心动画层中显示像素缓冲区的内容。

要将缓冲区转换为图像,首先需要将缓冲区转换为
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))