我正在努力在 iOS 10 中添加对广色域照片的支持。当用户从相机拍摄照片时,我需要使用支持新色彩空间的新 API 来保存照片数据 - UIGraphicsImageRenderer
'sjpegData
而不是UIImageJPEGRepresentation
.
我在图像方向上遇到了一些麻烦。在我的 iPad 上以纵向拍摄照片,图像未正确绘制。请参阅以下评论:
旧 API:
let image = info[UIImagePickerControllerOriginalImage] as! UIImage
let imageData = UIImageJPEGRepresentation(image, 1)
新 API:
let image = info[UIImagePickerControllerOriginalImage] as! UIImage
let cgImage = image.cgImage!
let ciImage = CIImage(cgImage: cgImage)
let format = UIGraphicsImageRendererFormat()
format.scale = 1
format.prefersExtendedRange = true
let renderer = UIGraphicsImageRenderer(bounds: ciImage.extent, format: format)
let imageData = renderer.jpegData(withCompressionQuality: 1, actions: { context in
context.cgContext.draw(cgImage, in: ciImage.extent) //draws flipped horizontally
//image.draw(at: .zero) //draws rotated 90 degrees leaving black at bottom
//image.draw(in: ciImage.extent) //draws rotated 90 degrees stretching and compressing the image to fill the rect
})
UIImageJPEGRepresentation
用UIGraphicsImageRenderer
's替换的正确方法是jpegData
什么?