Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the size of the crop rect when using UIImagePickerController

I need to change the size of the cropping rect when using UIImagePickerController. In my case, I need the user to select images that are 320x385 but the crop rect currently only allows 320x320 (when allow editing is on).

Any ideas?

like image 262
Justin Kredible Avatar asked Dec 17 '09 04:12

Justin Kredible


1 Answers

I have done a similar project. You have to use an image controller. Above your image controller you have to add another image controller (just because this is your crop area) aboveImageController's unfilled/empty part is where you will take. (so you should have an image with 320x480 sized and 320x385 empty in it.)

UIImage *image=theimageView.image;  
CGSize newSize;
newSize.width=320;
newSize.height=385;
UIGraphicsBeginImageContext(newSize);

//x=0 (because widhth : 320) y=0 (aboveImageController's empty part's start) 
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)]; 
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

CGImageRef imageRef = CGImageCreateWithImageInRect([newImage CGImage], rect);
UIImage *img = [UIImage imageWithCGImage:imageRef]; 
CGImageRelease(imageRef);
like image 94
Mihriban Minaz Avatar answered Nov 13 '22 02:11

Mihriban Minaz