【问题标题】:use UIImageWriteToSavedPhotosAlbum to save image , but the memory is full ,how can i catch the error code使用 UIImageWriteToSavedPhotosAlbum 保存图像,但内存已满,如何捕获错误代码
【发布时间】:2016-08-03 06:02:51
【问题描述】:

我正在使用此代码:

UIImageWriteToSavedPhotosAlbum(_curView.image, self,@selector(image:didFinishSavingWithError:contextInfo:), nil);

将图像保存到相册。每当我的设备内存已满时,我都会使用此选择器:

-(void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo

但它并没有识别出错误,实际上error 是nil。 发生错误时,我的设备内存已满。

如何检测内存是否可用?

【问题讨论】:

标签: ios objective-c memory


【解决方案1】:

如果您编辑要为其启用僵尸的方案(在“产品”菜单中,选择“编辑方案”),请转到左侧面板中的“应用程序.app”阶段,然后选择“参数”右侧的选项卡。然后,您可以将 NSZombieEnabled 添加到“环境变量”部分并将值设置为 YES,就像在 Xcode 3 中一样。

在 Xcode 4.1 及更高版本中,“运行”阶段的“诊断”选项卡上还有用于“启用僵尸对象”的复选框。

【讨论】:

    【解决方案2】:

    你可以试试这个,在保存图片到相册时使用回调方法来跟踪任何错误。

    (void)processImage:(UIImage *)image {
        [image retain];
        UIImageWriteToSavedPhotosAlbum(reconstructedImage, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL);
    }
    
    (void)image:(UIImage *) image didFinishSavingWithError: (NSError *) error contextInfo: (void *) contextInfo {
        NSLog(@"SAVE IMAGE COMPLETE");
        if(error != nil) {
            NSLog(@"ERROR SAVING:%@",[error localizedDescription]);
        }
    }
    

    【讨论】:

    • OP 说错误为零,所以我认为它不会进入您的 error!=nil
    【解决方案3】:

    我遇到了同样的问题。您似乎无法直接从UIImageView 保存图像。您需要拍摄快照并保存它。斯威夫特 3 示例:

    func takeSnapshot() -> UIImage? {
        UIGraphicsBeginImageContextWithOptions(imageView.bounds.size, false, UIScreen.main.scale);
    
        imageView.drawHierarchy(in: imageView.bounds, afterScreenUpdates: true)
        let image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return image;
    }
    

    【讨论】:

      猜你喜欢
      • 2016-06-20
      • 1970-01-01
      • 2011-11-07
      • 2011-05-26
      • 1970-01-01
      • 1970-01-01
      • 2017-12-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多