从相机点击多个图像时收到内存警告

时间:2015-07-06 11:28:00

标签: ios objective-c ios7 ios8.1

我正在使用自定义相机点击多个图像。现在点击几张图片后我收到内存警告,我的应用程序没有崩溃。任何人都可以帮我解决这个问题。我的代码如下所示

CImage = (UIImage *)[info objectForKey:UIImagePickerControllerOriginalImage];


[arrimages addObject: CImage];





if (aPicker.sourceType == UIImagePickerControllerSourceTypeCamera) {
    custvw.cameraButton.enabled = YES;


}
else
{


    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {

        [self.popoverController dismissPopoverAnimated:true];
        NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];

        [self dismissViewControllerAnimated:YES completion:nil];

        if ([mediaType isEqualToString:(NSString *)kUTTypeImage])
        {
            if (picker.sourceType==UIImagePickerControllerSourceTypePhotoLibrary)
            {

                [self.picker dismissViewControllerAnimated:YES completion:nil];

            }

            else
            {





            }


        }
        else if ([mediaType isEqualToString:(NSString *)kUTTypeMovie])
        {
        }
    }

            else
    {
        [self.picker dismissViewControllerAnimated:YES completion:nil];


    }


    }

1 个答案:

答案 0 :(得分:0)

通过将所选图像添加到阵列中来保存所选图像并不是一个好主意。这些图像通常非常耗费内存,很容易填满内存。

[arrimages addObject: CImage];

可能的解决方案:

  • 缩放图片

从UIImagePickerControllerDelegate检索图像后缩放图像 - imagePickerController:didFinishPickingMediaWithInfo:还有助于减少内存占用。

How to adjust a image size after using UIImagePickerController take a photo?

  • 将图像保存到磁盘

不要将图像保存在内存中,而是将它们保存到磁盘中,并在需要时从磁盘中获取。

iPhone - UIImagePickerController -> save the image to app folder