I have Swift code that uses the UIImagePickerController to have the user select a photo, a CIFilter is applied, then that UIImage is applied to a UIImageView. The problem is that I have no idea how make that image be in the correct orientation shown in the UIImagePickerController or in the Photos app. It's independent of the UIImage's imageOrientation. For instance, two different photos imported with a imageOrientation of "0" that are both portrait can resolve as a new UIImage with two completely different orientations. Maybe this is determined by EXIF information? Maybe it's both? That's why it's confusing.
Ultimately, I just want to have this image imported in the orientation shown in the UIImagePickerController or Photos app. If they can do it, there's some way I can.
@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
}
})
}