我想拍摄具有固定分辨率的图像。需要强制用户裁剪图像。我需要一个方形图像。
我正在使用下一个代码,它只是通过宽屏分辨率裁剪。
self.imagepicker = [[UIImagePickerController alloc]init];
self.imagepicker.delegate = self;
self.imagepicker.allowsEditing=YES;
self.imagepicker.preferredContentSize = CGSizeMake(200, 200);
self.imagepicker.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:self.imagepicker animated:YES completion:nil];
答案 0 :(得分:1)
preferredContentSize
不是UIImagePickerController本身的属性,而是任何UIViewController的属性,因为它嵌入在UIPopoverController中。
您需要自己展示裁剪界面。
答案 1 :(得分:0)
如果您想在选择图像后完成,请尝试使用此代码作为中心裁剪图像
- (UIImage *)squareImageFromImage:(UIImage *)image scaledToSize:(CGFloat)newSize1
{
CGAffineTransform scaleTransform;
CGPoint origin;
CGFloat newSize;
if (image.size.width > image.size.height)
{
newSize=image.size.height;
CGFloat scaleRatio = newSize / image.size.height;
scaleTransform = CGAffineTransformMakeScale(scaleRatio, scaleRatio);
origin = CGPointMake(-(image.size.width - image.size.height) / 2.0f, 0);
}
else
{
newSize=image.size.width;
CGFloat scaleRatio = newSize / image.size.width;
scaleTransform = CGAffineTransformMakeScale(scaleRatio, scaleRatio);
origin = CGPointMake(0, -(image.size.height - image.size.width) / 2.0f);
}
CGSize size = CGSizeMake(newSize, newSize);
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
UIGraphicsBeginImageContextWithOptions(size, YES, 0);
} else {
UIGraphicsBeginImageContext(size);
}
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextConcatCTM(context, scaleTransform);
[image drawAtPoint:origin];
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
对你有帮助。感谢