[英]CVPixelBufferRef to NSImage
如何將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))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.