在didFinishPickingMediaWithInfo中,我正在规范图像,但是当我拍照时,我收到内存警告并在某些设备中崩溃。为什么呢?
- (void) imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
// Save image
image = [self normalizedImage:image];
// UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
self.image = image;
[self salvarImagem:image];
}
- (UIImage *)normalizedImage:(UIImage*)imgtratar {
if (imgtratar.imageOrientation == UIImageOrientationUp) return imgtratar;
UIGraphicsBeginImageContextWithOptions(imgtratar.size, NO, imgtratar.scale);
[imgtratar drawInRect:(CGRect){0, 0, imgtratar.size}];
UIImage *normalizedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return normalizedImage;
}
编辑:我已经搜索过,解决方案对我不起作用......
我调试了,错误在
[imgtratar drawInRect:(CGRect){0, 0, imgtratar.size}];
答案 0 :(得分:0)
也许是因为你忘了这行
[self dismissModalViewControllerAnimated:YES];
在UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
和/或压缩并将图像转换为JPEG格式。检查UIImageJPEGRepresentation(UIImage *image, CGFloat compressionQuality)
。
N.B。请先搜索现有解决方案。你会在here
中找到一些here,here和很多答案 1 :(得分:0)
我解决了调整图像大小的问题...问题是因为图像太大了
- (UIImage *)normalizedImage:(UIImage*)imgtratar {
if (imgtratar.imageOrientation == UIImageOrientationUp) return imgtratar;
UIGraphicsBeginImageContext(CGSizeMake(117, 175));
[imgtratar drawInRect:(CGRect){0, 0, 117, 175}];
UIImage *normalizedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return normalizedImage;
}