2012-04-25 123 views

回答

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))