UIImagePicker相机内存警告停止图像被设置为UIImageView

问题描述:

我有一个模式,显示UIImagePicker,并允许用户拍摄照片,然后将其放入UIImageView。UIImagePicker相机内存警告停止图像被设置为UIImageView

每隔一段时间我都会收到一条内存警告“收到内存警告”,并且UIImageView没有被分配。该应用程序相当简单,并没有使用大量的内存,并且很多时候这与ImagePicker作为一个独立的进程有关。这仅在使用相机时发生,并且发生在大约五分之一的时间。

有一个lot of talk about this online,大部分答案都表示'正确处理警告';但我不知道这意味着什么 - 我只是想要拍摄的照片显示在ImageView!它似乎发生之前,我可以在UIImagePicker代表做任何事情。

我该怎么做才能减轻这个?

这里的didFinishPickingImage代表:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)selectedImage editingInfo:(NSDictionary *)editingInfo { 
    //set background for image select button, put image reference somewhere to copy image to documents folder and insert into modular's sentence object. 
    //ImagePicker.jpg needs it's border set to 1px black. 

    NSLog(@"imagePickerController: selectedimage: %@", selectedImage); 

    imageViewBehindPhotoBigButton.clipsToBounds = YES; 
    [imageViewBehindPhotoBigButton.layer setBorderColor: [[UIColor blackColor] CGColor]]; 
    [imageViewBehindPhotoBigButton.layer setBorderWidth: 1.0]; 
    [imageViewBehindPhotoBigButton setBackgroundColor:[UIColor whiteColor]]; 

    [imageViewBehindPhotoBigButton setContentMode: UIViewContentModeScaleAspectFill]; 
    imageViewBehindPhotoBigButton.image = selectedImage; 

    imageViewBehindPhotoBigButton.hidden = NO; 
    [choosePhotoBigButton setBackgroundImage:nil forState:UIControlStateNormal]; 

    choosePhotoBarImage.hidden = NO; 
    choosePhotoText.hidden = NO; 

    addButton.enabled = YES; 

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {  
     //because iPad uses a pop up - we don't want to dismiss modals here! 
     [imagePopupController dismissPopoverAnimated:YES]; 

    }else{ 
     [self dismissModalViewControllerAnimated:YES];  
    } 



} 

答案是缩放/处理来自的UIImagePickerController图像时实现线程有,我用here一个很好的讨论

+0

您好,感谢。你的 链接。到目前为止,它似乎工作 - 没有“内存警告”。在我登陆这里之前,我也想到了这一点,但是阻止我这么做的原因是因为我认为它可能会消耗更多的处理汁/内存,同时缩小图像,但它似乎工作。再次感谢。 – Unheilig 2013-07-14 10:46:28