UIImagePickerController - crops picture to square (in portrait)

28,961

Solution 1

Check out GKImagePicker library, it allows to set your custom image crop area, like this:

self.imagePicker = [[GKImagePicker alloc] init];
self.imagePicker.cropSize = CGSizeMake(320, 90);
self.imagePicker.delegate = self;

[self presentModalViewController:self.imagePicker.imagePickerController animated:YES];

Solution 2

I know its really late to answer this question, But someone may find this helpful.

Change

[imagePicker setAllowsEditing:YES]; 

To

[imagePicker setAllowsEditing:NO];

Thanks, Jay

Solution 3

You can provide a custom cropping UI, but there is no way to change just the cropping rectangle of the standard one.

This link might help with that.

Share:
28,961
cabhara
Author by

cabhara

Mobile Developer: iOS and Android natively, Unity and React Native. Original from Germany, living in the US.

Updated on July 05, 2022

Comments

  • cabhara
    cabhara almost 2 years

    I'm using the UIImagePickerController to take and edit a picture. it works fine in landscape, but in portrait it will crop the picture into a square (does not allow to reduce the image to fit fully into the square crop field like in landscape. Any ideas?

    code:

    -(IBAction)initCamera:(id)sender{
    
    //Init imagePicker instance
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
    [imagePicker setDelegate:self];
    
    [imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
    [imagePicker setShowsCameraControls:YES];
    [imagePicker setAllowsEditing:YES];
    
    [self presentModalViewController:imagePicker animated:YES];
    [imagePicker release];
    }
    
  • cabhara
    cabhara about 12 years
    Thanks. I'm just wondering why cropping works ok for landscape (I can fit the whole image into the cropping square, so nothing gets lost), but not for portrait, where it doesn't allow to fit the image into the square.
  • George
    George almost 11 years
    it doesn't allow to set camera as sourcetype. It works with gallery only!
  • Andrey Zverev
    Andrey Zverev over 10 years
    @George it allows to use images from both gallery and camera.
  • Josh Lehman
    Josh Lehman over 10 years
    I updated the answer to include a sample line for setting sourceType
  • Recycled Steel
    Recycled Steel over 10 years
    @JoshLehman I am having same problem and this looks perfect but I can not see how you can set the source.
  • Bms270
    Bms270 over 10 years
    @RecycledSteel You should use self.imagePicker.imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
  • carbocation
    carbocation over 8 years
    This simply disables cropping. Imagine a use-case where someone wanted to upload a full-size portrait, yet wanted to crop out parts of a landscape photo.
  • Jay Pandya
    Jay Pandya over 8 years
    @carbocation yes that can be a case. But thats whole new functionality i guess, that you can manage by checking imageOrientation property of image in didFinishPickingImage: delegate method of UIImagePickerController
  • ios
    ios about 8 years
    When i add GK Library and images , it gives me errors . What to do .?