gpt4 book ai didi

ios - 如何使用 Swift 创建带有 kCVPixelFormatType_32BGRA 格式化缓冲区的 UIImage

转载 作者:行者123 更新时间:2023-11-28 14:34:10 46 4
gpt4 key购买 nike

我们正在使用以下代码从缓冲区创建 UIImage

let context = CGContext(data: baseAddress, width: frameWidth, height: frameHeight, bitsPerComponent: 8, bytesPerRow: bytesPerRow, space: colorSpace, bitmapInfo: bitmapInfo.rawValue)!

let cgImage0 = context.makeImage()
let uiImage0 = UIImage(cgImage: cgImage0!)

问题是我们只能使用 kCVPixelFormatType_32BGRA 格式使用 AVCaptureVideoDataOutput() 创建彩色图像缓冲区,这是与 kCVPixelFormatType_32RGBA 最相似的格式

在某些时候我们需要 UIImage 并且我们需要将缓冲区转换为 UIImage 并且因为 UIImage 是 RGBA 格式的颜色已经失真。

我们如何从缓冲区获取 kCVPixelFormatType_32RGBA 格式的 UIImage。

最佳答案

通过制作

   var bitmapInfo  = CGBitmapInfo.byteOrder32Little.rawValue
bitmapInfo |= CGImageAlphaInfo.premultipliedFirst.rawValue & CGBitmapInfo.alphaInfoMask.rawValue

代替

   var bitmapInfo  = CGBitmapInfo(rawValue: CGImageAlphaInfo.premultipliedLast.rawValue)

但是从 Apple 文档中获取这个非常困难。

关于ios - 如何使用 Swift 创建带有 kCVPixelFormatType_32BGRA 格式化缓冲区的 UIImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51020777/

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