I am using an UIImagePickerController
with allowsEditing
property sat to true:
let imagePickerController = UIImagePickerController()
imagePickerController.delegate = self
imagePickerController.allowsEditing = true
imagePickerController.sourceType = .photoLibrary
present(imagePickerController, animated: true, completion: nil)
My problem is that when I select a crop area for the image the resulting image is wrong.
This is what I select:
However, this is the image that I get:
As you can see the image is wrong, especially the bottom and right size.
In my UIImagePickerControllerDelegate
method I have this:
imageView.image = info[.editedImage] as? UIImage
Here is some data from the info
dictionary:
let originalImage = info[.originalImage] as? UIImage
let editedImage = info[.editedImage] as? UIImage
let cropRect = (info[.cropRect] as? NSValue)!.cgRectValue
NSLog("originalImage size: \(originalImage!.size)")
NSLog("editedImage size: \(editedImage!.size)")
NSLog("cropRect size: \(cropRect)")```
This gives me:
originalImage size: (2320.0, 3088.0)
editedImage size: (1242.0, 1242.0)
cropRect size: (211.0, 557.0, 2309.0, 2309.0)
If anybody can see the logic in these numbers I would love to hear it. Shouldn't the size in crop rect be the same as the size of the edited image?
PS: I have seen several questions regarding wrong crop size, but they are all related to the status bar issue and are only vertical (i.e. no black bar on the right like mine).