1

I am working on camera app. I am capturing an image by using UIImagePickerController.After that before saving it in gallery I want to crop the image and need to save the cropped image in gallery.

I searched on google ,I found samples to pick the images from gallery and then cropping which is not my requirement.Could any body have worked on this??? If you have gone through any tutorials/sample code please post the links.Thanks in advance

  • 2
    Possible Duplicate http://stackoverflow.com/a/9529786/767730 – Anupdas Mar 08 '13 at 06:37
  • after capturing the image its getting saved in gallery..@Brukhard – Satya Swaroop Basangi Mar 08 '13 at 06:38
  • This has been incorrectly marked as a duplicate. The question refers to cropping the preview image that the iOS UIImagePickerController shows to the user before they save it. It also refers to capturing the image with the camera, so the answers below about the built in editing feature do not apply. – Lee Probert Jul 23 '18 at 16:09

2 Answers2

1

pust isallowediting=yes; for picker so that we can edit image which you captured and selected from gallery also

UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    picker.delegate = self;
    picker.isallowediting = yes;  

hope these will help you

ganesh manoj
  • 977
  • 10
  • 24
0

Use this code in imagePickerController method to crop your captured image. It's working fine for me.

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
    {
    [_imagePickerControllerInstance dismissModalViewControllerAnimated:YES];
        UIImage *_pickedAvatar = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

       UIImage *croppedImage = [self cropImage:_pickedAvatar andFrame:CGRectMake(0, 0, 250, 250)];

   // croppedImage : U can use this cropped image for saving in gallery.

    }
- (UIImage *)cropImage:(UIImage*)image andFrame:(CGRect)rect {

   //Note : rec is nothing but the image frame which u want to crop exactly. 

    rect = CGRectMake(rect.origin.x*image.scale,
                      rect.origin.y*image.scale,
                      rect.size.width*image.scale,
                      rect.size.height*image.scale);

    CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], rect);
    UIImage *result = [UIImage imageWithCGImage:imageRef
                                          scale:image.scale
                                    orientation:image.imageOrientation];
    CGImageRelease(imageRef);
    return result;
}

else

See this question.

Use UIImage category and use wherever you need to crop image.

@implementation UIImage (Crop)
    - (UIImage *)crop:(CGRect)rect {

        rect = CGRectMake(rect.origin.x*self.scale, 
                          rect.origin.y*self.scale, 
                          rect.size.width*self.scale, 
                          rect.size.height*self.scale);       

        CGImageRef imageRef = CGImageCreateWithImageInRect([self CGImage], rect);
        UIImage *result = [UIImage imageWithCGImage:imageRef 
                                              scale:self.scale 
                                        orientation:self.imageOrientation]; 
        CGImageRelease(imageRef);
        return result;
    }

@end
halfer
  • 19,824
  • 17
  • 99
  • 186
Ganapathy
  • 4,594
  • 5
  • 23
  • 41