gpt4 book ai didi

macos - CVPixelBufferRef 到 NSImage

转载 作者:行者123 更新时间:2023-12-03 16:06:47 24 4
gpt4 key购买 nike

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

最佳答案

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

关于macos - CVPixelBufferRef 到 NSImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10318260/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com