How to use UIImagePickerControllerCropRect

风流意气都作罢 提交于 2019-12-04 03:43:23

You cannot do this using the built in UIImagePickerController functionality. Unfortunately, you can't control the size of the crop box.

Here is a project on github that may help you accomplish what you are looking to do (checkout YSImageCrop.h).

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

Suresh.D

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];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!