在相机UIImagePickerController中收到内存警告

时间:2012-10-11 06:35:56

标签: ios memory camera uiimagepickercontroller

当我进入相机UIImagePickerController时,我得到一条内存警告消息,我不知道如何解决这个问题。

这是我的代码:

    -(IBAction)addImageCamera:(id)sender
    {
        if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
        {
            pickerImgCamera.sourceType = UIImagePickerControllerSourceTypeCamera;
            cameraView.image=[img imageFromMainBundleFile:@"frameCam.png"];
            pickerImgCamera.cameraOverlayView=cameraView;

            [self.navigationController presentModalViewController:pickerImgCamera animated:NO];

        }
        else
        {
            UIAlertView*alert=[[UIAlertView alloc] initWithTitle:@"Oops" message:@"Camera not found" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
            [alert show];
            alert=nil;
        }
    }


 - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
    {
        UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];

        if (picker.sourceType == UIImagePickerControllerSourceTypeCamera)
        {
            [self dismissModalViewControllerAnimated:YES];

            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
                UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);

            });
        }

        [photoImage setImage:image];
    } 

注意:内存警告出现在iphone和ipad中。

2 个答案:

答案 0 :(得分:0)

根据我的经验,iPhone相机经常会触发内存警告,尤其是在旧设备上。当你进行调试时,它更有可能发生 - 诀窍是处理警告和摆脱不重要的东西。

答案 1 :(得分:-2)

如果图片质量在您的应用中不那么重要,请将uiimagepickercontroller的videoQuality设置为UIImagePickerControllerQualityTypeLow。这将减少应用程序中的内存警告。