Search code examples
iosimagealassetslibraryphotolibrary

Error occuring when loading photolibrary images : ERROR: FigCreateCGImageFromJPEG returned -12910. 423114 bytes. We will fall back to software decode


I'm working with an application in which I'm loading images from photolibrary.

I'm using the following code for binding the image to 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];
}

But when I tried to run it, an error is coming and the application is crashing sometimes. The error printed on console is:

** * ERROR: FigCreateCGImageFromJPEG returned -12910. 423114 bytes. We will fall back to software decode. Received memory warning. My photo library contains high resolution images and their size between 10-30 MB.


Solution

  • Finally I fixed the issue. I think the issue is with fetching the full resolution image.

    Instead of :

    CGImageRef iref = [rep fullResolutionImage];

    I used:

    CGImageRef iref = [myasset aspectRatioThumbnail];
    

    And everything worked fine. No error in console, no crash, but quality/resolution of the image is reduced.