I am using UIImagePickerController to capture image using camera. Supported orientation for my app is Portrait. I am seeing strange behavior for iPhone 5. I am using Xcode 7 and swift 2.0. iPhone 5 OS version is 8.4. Deployment Target is 8.0 for my app.
Issues are. 1. For iPhone 5, after capturing image, image is shown in respective mode in which image is captured. But After I press 'Use Photo' standard option and when image is displayed on UIImageView, image is automatically rotated to left. Don't know why. If I choose image from photo library, image is not rotated. I don't want image to be rotated. I seen similar post with better explanation and actual image but is not answered. UIImageView rotates image with retina 4 iPhone simulator but not retina 3.5/regular simulator I tried almost all swift solution from this post : iOS UIImagePickerController result image orientation after upload and other post too but nothing seems to be working. I used shouldAutorotate(), sFunc_imageFixOrientation(), and adding extension from this post.
- Also, for both device, after pressing 'Use Photo' option, it takes around 10 second to upload image. Can it be done faster.
Here is my code:
func openCamera() {
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera) {
dispatch_async(dispatch_get_main_queue(), {
let imagePicker = UIImagePickerController();
imagePicker.sourceType = UIImagePickerControllerSourceType.Camera;
imagePicker.allowsEditing = false;
imagePicker.delegate = self;
imagePicker.modalPresentationStyle = .FormSheet
self.presentViewController(imagePicker, animated: true, completion: nil);
});
}
}
func openGallary() {
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.PhotoLibrary) {
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary;
imagePicker.allowsEditing = true
self.presentViewController(imagePicker, animated: true, completion: nil)
}
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!) {
profileImage?.image = image
self.dismissViewControllerAnimated(true, completion: nil);
}
This is what I observed. When you capture image using camera, image is rotated counterclockwise by 90 degree and image orientation is set to UIImageOrientation.Up so code from function sFunc_imageFixOrientation iOS UIImagePickerController result image orientation after upload will not work. If you select image from photo library, then image will be displayed as it is.
Modified function:
Call this function only if image is captured from Camera. I know my answer will not be perfect but you can definitely try if nothing is working out for you.