【发布时间】:2020-10-29 22:41:17
【问题描述】:
TL;DR:iOS14 中的 ARKit capturedImage 发生了一些变化,我们无法使其适应我们的流程。
使用 Xcode 12 GM 构建,在 iPhone 6S 14.0 上测试。
我们已经实现了将ARFrame 转换为Data 的流程,这对于尚未升级到iOS14 的设备非常有效。
我们收到ciImage 喜欢:
extension ARFrame {
var ciImage: CIImage { CIImage(cvPixelBuffer: capturedImage) }
}
我们输入ImageConverter:
public class ImageConverter {
lazy var imageContext = CIContext(mtlDevice: MTLCreateSystemDefaultDevice()!)
lazy var colorSpace = CGColorSpace(name: CGColorSpace.sRGB)
public func jpgData(for image: CIImage) -> Data {
guard let colorSpace = colorSpace else { return Data() }
if let jpegRepresentation = imageContext.jpegRepresentation(of: image,
colorSpace: image.colorSpace ?? colorSpace) {
return jpegRepresentation
} else {
return Data()
}
}
}
所以,问题是,当我们调用.jpegRepresentation 时,它会发出警告:
findWriterForType:128: unsupported file format 'public.heic'
虽然jpegRepresentation 不是 nil,但它不适用于我们的服务器,它需要 jpeg 数据(仍然适用于 iOS13.7 或更低版本的设备)。
到目前为止我们尝试了什么:
if let heifRepresentation = imageContext.heifRepresentation(of: image,
format: .RGBA8,
colorSpace: image.colorSpace ?? colorSpace) {
return heifRepresentation
}
返回 nil,并使用 .jpegRepresentation 引发相同的错误。也试过其他格式,没用。
【问题讨论】: