UIImagePickerController AllowsEditing not working

Amit Raz picture Amit Raz · Jan 9, 2014 · Viewed 25.5k times · Source

I am using UIImagePickerController to allow the user to take a picture. I want to allow him/her to edit it afterwards but, whatever I do, I get nothing.

Here is my code (I am using Xamarin):

UIImagePickerController imagePicker = new UIImagePickerController ();
                // set our source to the camera
                imagePicker.SourceType = UIImagePickerControllerSourceType.Camera;
                // set what media types
                //imagePicker.MediaTypes = UIImagePickerController.AvailableMediaTypes (UIImagePickerControllerSourceType.Camera);
                // show the camera controls
                imagePicker.ModalPresentationStyle = UIModalPresentationStyle.CurrentContext;
                imagePicker.ShowsCameraControls = true;
                imagePicker.AllowsEditing = true;
                imagePicker.SetEditing (true,true);
                imagePicker.PreferredContentSize = new SizeF(900,600);
                imagePicker.CameraCaptureMode = UIImagePickerControllerCameraCaptureMode.Photo;
                imagePicker.Title="taste.eat. image";
                // attach the delegate
                imagePicker.Delegate = new ImagePickerDelegate();
                // show the picker
                NavigationController.PresentViewController(imagePicker, true,null);

Am I missing something?

EDIT:

I have followed the tutorial and I am getting to the screen with the rectangle, but if i pan or zoom it just snaps back to the center once I lift my finger. Is it possible to get to this screen from the photos application?

Image from the photos application

Answer

Aditya Mathur picture Aditya Mathur · May 20, 2014

When using UIImagePickerController's delegate method - imagePickerController:didFinishPickingMediaWithInfo:, we get the image using

UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];

This code will always return the original image, even if editing is ON.

Try using

UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];

This will return the edited image if editing is ON.

Hope this helps.