2012-04-25 3 views
6

어떻게 CVPixelBufferRef를 NSImage 또는 CGImageRef로 변환 할 수 있습니까? Core Animation Layer에서 픽셀 버퍼의 내용을 표시 할 수 있어야합니다.CVPixelBufferRef to NSImage

답변

0

버퍼를 이미지로 변환하려면 먼저 버퍼를 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))