ios - 如何将从 UIImagePickerController 获取的图像保存为 HEIF 文件?

标签 ios ios11 heif

如何将从 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/

相关文章:

ios - HEIF 媒体可以流式传输吗?

ios - 如何检测来自另一个类的 touchesBegan、touchesMoved、touchesEnded 事件

iphone - 使用 SLServiceTypeFacebook 时从 SLComposeViewController 获取 UITextView

ios - NSMutableArray 高 CPU 使用率

crash - 使用NSString方法boundingRectWithSize时在iOS 11上崩溃

push-notification - 我们可以在 ios serviceworker 上运行 firebase 实时监听吗?

ios - 如何在类型扩展方法中实例化类型?

ios - 自 iOS 11 以来 RefreshControl 刷新后的粘性 UINavigationbar

ios - UIImage 是否支持 HEIC/HEIF

java - 将 HEIF 图像转换为 Java 中更常见的图像格式