Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIImagePickerController AllowsEditing not working

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

like image 841
Amit Raz Avatar asked Jan 09 '14 15:01

Amit Raz


3 Answers

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.

like image 121
Aditya Mathur Avatar answered Oct 05 '22 04:10

Aditya Mathur


The AllowsEditing property simply allows the user to crop to a square if picking an image and trim the video if picking a video.

Any other functionality needs to be implemented with custom UI and code.

See this question:iPhone SDK - How to customize the crop rect in UIImagePickerController with allowsEditing on?

What you are showing in the screenshot is not part of UIImagePickerController, unfortunately

like image 27
Jack Avatar answered Oct 05 '22 03:10

Jack


SWIFT 3

I was having a hard time returning the cropped image (simple mistake on my end). Instead of using UIImagePickerControllerOriginalImage, you need UIImagePickerControllerEditedImage. See below:

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
    // The info dictionary contains multiple representations of the image, and this uses the cropped image.
    let selectedImage = info[UIImagePickerControllerEditedImage] as! UIImage

    // Set yourImageView to display the selected image.
    yourImage.image = selectedImage

    // Dismiss the picker.
    dismiss(animated: true, completion: nil)
}
like image 33
A.J. Hernandez Avatar answered Oct 05 '22 05:10

A.J. Hernandez