如何在捕获图像时从选定区域中的 UIImagePickerController 裁剪图像。覆盖 View 到 UIImagePickerController
Best Answer-推荐答案 strong>
代码下方
-(UIImage *)centerCropImageUIImage *)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)imagePickerControllerUIImagePickerController *)picker didFinishPickingMediaWithInfoNSDictionary *)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];
}
关于ios - 从选定区域中的 uiimagepickerviewcontroller 裁剪图像,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/26628169/
|