从图像选择器获取图像会导致内存警告

时间:2013-03-25 23:52:41

标签: iphone ios objective-c cocoa-touch uiimage

我正在开发一款需要缩略图版本和从UIImagePickerController中选择的图像的压缩完整版本的应用。选择相对较大的图像(例如iPhone 4S相机拍摄的图像)时,会收到内存警告。我无法确定它是来自调整大小算法还是实际从拾取器获取图像。可以做些什么来防止这种情况?必须有一个解决方案,因为在无数的应用程序中使用了一个简单的照片选择器。

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

    //show a progress hud while the image is retrieved 
    [SVProgressHUD showWithStatus:@"Getting Picture" maskType:SVProgressHUDMaskTypeGradient];

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{

        UIImage *originalImage = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

        //currentImage = [originalImage scaleToSize:CGSizeMake(100.0f, 100.0f)];

        CGSize size = CGSizeMake(51, 43);
        UIGraphicsBeginImageContext(size);
        [originalImage drawInRect:CGRectMake(0, 0, 51, 43)];
        currentImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();

        compressedFullImage = UIImagePNGRepresentation(originalImage);

        imageHasBeenSelected = YES;

        dispatch_async(dispatch_get_main_queue(), ^{

            [picker dismissModalViewControllerAnimated:YES];
            [SVProgressHUD dismiss];
        });
    });
}

0 个答案:

没有答案