如何使用UIImagePickerControllerCropRect

我只是想出了一个方法来改变从UIImagePickerViewController捕获图像后出现的裁剪框的矩形。 这可以在UIImagePickerControllerCropRect帮助下完成。 但我不知道如何使用它。 裁剪框原来是方形的。 我想它是长方形的。

有人可以跟我分享一个例子吗?

你不能使用内置的UIImagePickerControllerfunction来做到这一点。 不幸的是,你无法控制裁剪框的大小。

这是一个在github上的项目 ,可以帮助你完成你正在做的事(检出YSImageCrop.h )。

基本上,底线是你必须自己实现UIImagePickerControllerfunction。 我相信UIImagePickerWithEditor项目是一个很好的开始。

是的,我们可以做到这一点。

像这样创build用户定义的函数:

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

并调用此代码:

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