如何裁剪捕获的图像,然后将其保存在IOS中的库中

我正在开发相机应用程序。 我通过使用UIImagePickerController捕获图像。之后,将其保存在画廊之前,我想裁剪图像,并需要保存在裁剪图像的画廊。

我search谷歌,我发现样本从图片库中select图片,然后裁剪哪些不是我的要求。任何机构都可以在这个? 如果您已经通过任何教程/示例代码请发布链接。提前感谢

pust isallowediting =是; 对于选取器,以便我们可以编辑您从图库中捕获和select的图像

UIImagePickerController *picker = [[UIImagePickerController alloc] init]; picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; picker.delegate = self; picker.isallowediting = yes; 

希望这些会帮助你

在imagePickerController方法中使用这个代码来裁剪所拍摄的图像。 它对我工作很好。

 - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { [_imagePickerControllerInstance dismissModalViewControllerAnimated:YES]; UIImage *_pickedAvatar = [info objectForKey:@"UIImagePickerControllerOriginalImage"]; UIImage *croppedImage = [self cropImage:_pickedAvatar andFrame:CGRectMake(0, 0, 250, 250)]; // croppedImage : U can use this cropped image for saving in gallery. } - (UIImage *)cropImage:(UIImage*)image andFrame:(CGRect)rect { //Note : rec is nothing but the image frame which u want to crop exactly. rect = CGRectMake(rect.origin.x*image.scale, rect.origin.y*image.scale, rect.size.width*image.scale, rect.size.height*image.scale); CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], rect); UIImage *result = [UIImage imageWithCGImage:imageRef scale:image.scale orientation:image.imageOrientation]; CGImageRelease(imageRef); return result; } 

其他

使用此链接

裁剪UIImage

使用UIImage类别,并使用任何你需要裁剪图像。

 @implementation UIImage (Crop) - (UIImage *)crop:(CGRect)rect { rect = CGRectMake(rect.origin.x*self.scale, rect.origin.y*self.scale, rect.size.width*self.scale, rect.size.height*self.scale); CGImageRef imageRef = CGImageCreateWithImageInRect([self CGImage], rect); UIImage *result = [UIImage imageWithCGImage:imageRef scale:self.scale orientation:self.imageOrientation]; CGImageRelease(imageRef); return result; } @end