Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use UIImagePickerControllerCropRect

I just figured out a way to change rect for crop box which appears after capturing an image from UIImagePickerViewController. This can be done with help of UIImagePickerControllerCropRect. But I have no idea how to use it. Originally the crop box is square. I want it to be rectangular.

Can someone share an example with me?

like image 562
Nitish Avatar asked Apr 11 '12 05:04

Nitish


1 Answers

Yes, we can do that.

Create the User defined Function like this:

- (UIImage *)imageByCropping:(UIImage *)imageToCrop toRect:(CGRect)rect
{
   CGImageRef imageRef = CGImageCreateWithImageInRect([imageToCrop CGImage], rect);

    UIImage *cropped = [UIImage imageWithCGImage:imageRef];
    CGImageRelease(imageRef);


    return cropped;

}

And call this code:

UIImage *img1=[self imageByCropping:img toRect:CGRectMake(0,0, 106.6, 106.6)];
UIImageView *image_view=[[UIImageView alloc] initWithImage:img1];
like image 104
Suresh D Avatar answered Nov 01 '22 20:11

Suresh D