0

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:

enter image description here

However, this is the image that I get:

enter image description here

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).

pajevic
  • 4,607
  • 4
  • 39
  • 73
  • 1
    This is a bug that has existed in iOS since iOS 6. Apple has chosen not to fix it. It has been raised in multiple radars and still nothing from Apple. Unfortunately there is no easy fix for this. – Fogmeister Mar 20 '19 at 06:27
  • I don't believe this is a duplicate of the linked question. First of all, he says it works with Photo Library but bot with Camera. Notice that I am using Photo Library. Second, his issue is that he cannot move the cropping rect, I actually can. My question is not about not being able to edit but about the editing result not matching the selection. He doesn't mention that at all. – pajevic Mar 20 '19 at 06:32
  • no. when they say they cannot move the crop text they mean what you mean here. It is a bug. I raised the bug with Apple and spent weeks looking into it. What you are experiencing here is the same thing. The best course of action is to file a radar with Apple and find another way to fix this. If you look in the comments of the selected answer you will find links to other radars. – Fogmeister Mar 20 '19 at 06:37
  • Look, I don't mean to be difficult, especially when someone is taking their time to look into an issue I am having, but you really seem to be wrong here. This is the literal first paragraph from the other question: "*I have a UIImagePicker that works perfect for a type of UIImagePickerControllerSourceTypePhotoLibrary, but when I use UIImagePickerControllerSourceTypeCamera, the editing box cannot move from the center of the image*." Also, he says "*So if the image is say taller than it is wide, the user cannot move the editing box to the top square of the image.*". I **can** do that. – pajevic Mar 20 '19 at 06:42

0 Answers0