我有Swift代码,该代码使用UIImagePickerController来让用户选择照片,然后应用CIFilter,然后将该UIImage应用于UIImageView。问题是我不知道如何使图像以UIImagePickerController或“照片”应用中显示的正确方向。它独立于UIImage的imageOrientation。例如,导入的imageOrientation为“ 0”的两张不同的照片(均为肖像)可以解析为具有两个完全不同的方向的新UIImage。也许这取决于EXIF信息?也许两者都有?这就是为什么令人困惑。
最终,我只想按照UIImagePickerController或“照片”应用中显示的方向导入此图像。如果他们能做到,我有一些办法。
@objc func imagePickerController(_ picker: UIImagePickerController!, didFinishPickingImage image: UIImage!, editingInfo: NSDictionary!) {
let selectedImage : UIImage = image
print("selectedImage.imageOrientation = \(selectedImage.imageOrientation.rawValue)")
let isPortrait:Bool = image.size.height > image.size.width ? true : false
dismiss(animated: true, completion: { () in
DispatchQueue.main.async {
self.enableButtons(enabled:false)
self.activityTextStatus?.setText("Preparing", center:self.view.center, addToView:self.loadingContainer, setRotation:true)
}
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
self.exportImagesToPreview(capturedImage: selectedImage,
orientation:nil,
isPortrait: isPortrait)
// here I apply an effect to the image,
// and it may be in the incorrect orientation
}
})
}