加载照片库图像时发生错误:错误:FigCreateCGImageFromJPEG 返回 -12910。 423114 字节。我们将退回到软件解码

Posted

技术标签:

【中文标题】加载照片库图像时发生错误:错误:FigCreateCGImageFromJPEG 返回 -12910。 423114 字节。我们将退回到软件解码【英文标题】:Error occuring when loading photolibrary images : ERROR: FigCreateCGImageFromJPEG returned -12910. 423114 bytes. We will fall back to software decode 【发布时间】:2012-12-24 03:54:48 【问题描述】:

我正在使用从照片库加载图像的应用程序。

我正在使用以下代码将图像绑定到 imageView。

-(void)loadImage:(UIImageView *)imgView FileName:(NSString *)fileName

   typedef void (^ALAssetsLibraryAssetForURLResultBlock)(ALAsset *asset);
   typedef void (^ALAssetsLibraryAccessFailureBlock)(NSError *error);    

   ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
   
     ALAssetRepresentation *rep = [myasset defaultRepresentation];
     CGImageRef iref = [rep fullResolutionImage];
     UIImage *lImage;
     if (iref)
     
        lImage = [UIImage imageWithCGImage:iref scale:[rep scale] orientation:(UIImageOrientation)[rep orientation]];   
     
     else
     
        lImage = [UIImage imageNamed:@"Nofile.png"];
     
     dispatch_async(dispatch_get_main_queue(), ^
         [imgView setImage:lImage];
     );
   ;

   ALAssetsLibraryAccessFailureBlock failureblock  = ^(NSError *myerror)
   
       UIImage *images = [UIImage imageNamed:@"Nofile.png"];
        dispatch_async(dispatch_get_main_queue(), ^
             [imgView setImage:images];
     );        
   ;                   


    NSURL *asseturl = [NSURL URLWithString:fileName];

    ALAssetsLibrary *asset = [[ALAssetsLibrary alloc] init];
    [asset assetForURL:asseturl
           resultBlock:resultblock
          failureBlock:failureblock];

但是当我尝试运行它时,会出现错误并且应用程序有时会崩溃。 控制台打印的错误是:

** * 错误:FigCreateCGImageFromJPEG 返回 -12910。 423114 字节。我们将回到软件解码。 收到内存警告。 我的照片库包含高分辨率图像,它们的大小在 10-30 MB 之间。

【问题讨论】:

我认为 10-30 兆是原始 jpg 文件的大小?记住...软件解码将解压缩为原始内存位图。一个 30meg 的 jpg 文件可能是 200-300meg 的未压缩/原始格式。 【参考方案1】:

最后我解决了这个问题。 我认为问题在于获取全分辨率图像。

而不是:

CGImageRef iref = [rep fullResolutionImage];

我用过:

CGImageRef iref = [myasset aspectRatioThumbnail];

一切正常。控制台没有错误,没有崩溃,但图像的质量/分辨率降低了。

【讨论】:

我需要保持质量,我应该怎么做才能消除这个错误..?有什么建议吗? @NikitaP:是的,使用上述方法存在质量问题。但是我没有更好的方法来做到这一点 我只收到过一次这个错误,当我再次运行应用程序时,它消失了:)。我不确定是什么原因造成的。【参考方案2】:

我也有类似的错误:

* 错误:FigCreateCGImageFromJPEG 返回 -12909。 0 字节。我们将退回到软件解码。

随叫随到的应用迷恋:

CGImageRef originalImage = [representation fullResolutionImage];

我通过替换来修复它:

CGImageRef originalImage = [representation fullScreenImage]; 

【讨论】:

【参考方案3】:
[UIImage imageWithCGImage:] 

imageWithCGImage是一个栈内存函数,如果大图好像会溢出。 使用堆函数怎么样?

lImage = [[[UIImage alloc]initWithCGImage:iref scale:[rep scale] orientation:(UIImageOrientation)[rep orientation]] autorelease];

【讨论】:

以上是关于加载照片库图像时发生错误:错误:FigCreateCGImageFromJPEG 返回 -12910。 423114 字节。我们将退回到软件解码的主要内容,如果未能解决你的问题,请参考以下文章

填充collectionView单元格图像时从Firebase加载错误的照片并非每次都发生

加载资源失败:服务器响应状态为 500(内部服务器错误)当我尝试上传图像时发生此错误

新上传的照片出现 404 错误。如果我停止然后运行网站,图像会加载

方向错误的照片

从 Google 照片库加载图像以进行裁剪

照片框架 - 如何从 PHAsset 获取图像的 CLLocation?