问题描述
我正在与一个应用程序一起使用,该应用程序正在从照相馆库加载图像.
I'm working with an application in which I'm loading images from photolibrary.
我正在使用以下代码将图像绑定到imageView.
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:
** *错误:FigCreateCGImageFromJPEG返回-12910. 423114字节.我们将退回到软件解码.收到内存警告.我的照片库包含高分辨率图像,其大小在10-30 MB之间.
** * 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.
推荐答案
最后,我解决了该问题.我认为问题在于获取完整分辨率的图像.
Finally I fixed the issue.I think the issue is with fetching the full resolution image.
而不是:
CGImageRef iref = [rep fullResolutionImage];
我用过:
CGImageRef iref = [myasset aspectRatioThumbnail];
一切正常.控制台中没有错误,没有崩溃,但是图像的质量/分辨率降低了.
And everything worked fine. No error in console, no crash, but quality/resolution of the image is reduced.
这篇关于加载光库图像时发生错误:错误:FigCreateCGImageFromJPEG返回-12910. 423114字节.我们将退回到软件解码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!