Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIImagePickerController edited image retrieves wrong image in iPad

I have UIImagePickerController to select/pick an image from the photo gallery. I have allowed UIImagePickerController to edit (selected) image (crop square frame of image), which works fine with iPhone but iPad can't provide properly edited (cropped) image.

I tried the following suggestion but could not find a solution:
iPad iOS7 - UIImagePickerController in UIPopoverController has wrong preview image

Here is code, that I've tried:

let imagePicker = UIImagePickerController()
imagePicker.allowsEditing = true

// Update (zoom) visibility of image using pinch gesture & retrieve image using delegate - didFinishPickingMediaWithInfo

//------------------------------------------
 func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {


     if let pickedImage = info[UIImagePickerControllerEditedImage] as? UIImage {
         // Wrong image - retrieves image different than actual visible in the editing window of picker view.
    }


    if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
        // Original image, visible perfect in iPad, when imagePicker.allowsEditing = false
    }


    picker.dismiss(animated: true) {
        // dismissing image picker
    }

}
like image 426
Krunal Avatar asked Oct 29 '22 10:10

Krunal


1 Answers

Add this method , you will get accurate result.

func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
    UIApplication.shared.isStatusBarHidden = true
}
like image 99
NIRAV BHAVSAR Avatar answered Nov 15 '22 07:11

NIRAV BHAVSAR