在采集图像时,如何在选定区域从UIImagePickerController中裁剪图像。到UIImagePickerController的覆盖视图
发布于 2014-10-29 10:58:03
低于“守则”
-(UIImage *)centerCropImage:(UIImage *)image
{
// Use smallest side length as crop square length
CGFloat squareLength = MIN(image.size.width, image.size.height);
// Center the crop area
CGRect clippedRect = CGRectMake((image.size.width - squareLength) / 2, (image.size.height - squareLength) / 2, squareLength, squareLength);
// Crop logic
CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], clippedRect);
UIImage * croppedImage = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
return croppedImage;
}其次在imagePickerViewDelegate方法中
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info objectForKey: @"UIImagePickerControllerOriginalImage"];
[self centerCropImage:image]; //Just give your image here for cropping
yourImage.image=image;
picker.delegate =self;
[picker dismissViewControllerAnimated:YES completion:nil];
}https://stackoverflow.com/questions/26628169
复制相似问题