我试图弄清楚用UIImagePickerController
拍摄照片后UIImage的大小是多少,以及如何正确缩放拍摄的图像。如果我希望相机每次拍摄100pt x 100pt的照片,我将如何做到这一点?
我为UIImagePickerController
咨询documentation,但图片尺寸没有任何内容
答案 0 :(得分:1)
我相信这样的事情就是你所追求的。如果我错了,请告诉我。
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
CGFloat var1;
CGFloat var2;
if (image.size.width > image.size.height){
// Landscape
CGFloat aspect = image.size.width / image.size.height;
CGFloat height = ceilf(100.0/aspect);
var1 = 100.0;
var2 = height;
}
else if (image.size.height > image.size.width){
// Portrait
CGFloat aspect = image.size.height / image.size.width;
CGFloat width = ceilf(100.0/aspect);
var1 = width;
var2 = 100.0;
}
else{
// Square
var1 = 100.0;
var2 = 100.0;
}
UIGraphicsBeginImageContextWithOptions(CGSizeMake(var1, var2), NO, 0.0);
[image drawInRect:CGRectMake(0, 0, var1, var2)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}