How to use UIImagePickerControllerCropRect

I just figured out a way to change the rectangle for the cropping frame that appears after capturing an image with a UIImagePickerViewController . This can be done using the UIImagePickerControllerCropRect . But I have no idea how to use it. The original crop box is square. I want it to be rectangular.

Can anyone share an example with me?

+8
ios iphone camera uiimagepickercontroller
source share
2 answers

You cannot do this using the built-in functionality of UIImagePickerController. Unfortunately, you cannot control the size of the crop field.

Here is a github project that can help you accomplish what you want to do (checkout YSImageCrop.h ).

Basically, the bottom line is that you need to implement the UIImagePickerController function yourself. I believe the UIImagePickerWithEditor project is a good place to start.

+3
source share

Yes, we can do it.

Create a user-defined function as follows:

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

And name this code:

 UIImage *img1=[self imageByCropping:img toRect:CGRectMake(0,0, 106.6, 106.6)]; UIImageView *image_view=[[UIImageView alloc] initWithImage:img1]; 
+6
source share

All Articles