如何将从 UIImagePickerController 获取的图像视为 HEIF 文件?现在使用相机作为源类型,UIImagePickerControllerOriginalImage 只为我提供了 UIImage。我想将 HEIF 格式的图像发送到服务器。这是假设 imageExportPreset 已设置为当前。
最佳答案
对于 sverin 的解决方案,我唯一要调整的是不使用 ctx.workingColorSpace,因为您可能正在更改图像实际所在的空间。例如,如果您将图像重新加载到 UIImageView 中,您可能会注意到这一点并且它看起来已经褪色了。
也针对 Swift 4 进行了更新。
do {
let ctx = CIContext()
let ciImage = CIImage(image: uiImage)
try ctx.writeHEIFRepresentation(of: ciImage!, to: url, format: .RGBA8, colorSpace: ciImage.colorSpace!, options: [:])
} catch {
print("ERROR", error.localizedDescription)
}
关于ios - 如何将从 UIImagePickerController 获取的图像保存为 HEIF 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47470419/