2012-04-25 17 views
6

CVPixelBufferRefをNSImageまたはCGImageRefに変換するにはどうすればよいですか?コア・アニメーション・レイヤーにピクセル・バッファーの内容を表示できる必要があります。CVPixelBufferRefから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)) 
関連する問題