我正在开发相机应用程序。我正在使用UIImagePickerController捕获图像。之后将其保存在库中我想裁剪图像并需要将裁剪后的图像保存在图库中。
我在谷歌搜索,我发现样本从画廊中挑选图像,然后裁剪,这不是我的要求。可以任何身体已经工作了吗???如果您已完成任何教程/示例代码,请发布链接。提前谢谢
答案 0 :(得分:1)
pust isallowediting = yes;对于选择器,以便我们可以编辑您从画廊中选择并从中选择的图像
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.delegate = self;
picker.isallowediting = yes;
希望这些能帮到你
答案 1 :(得分:0)
在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类别,并在需要裁剪图像的任何地方使用。
@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