我正在使用一个从照片库加载图像的应用程序。
我使用以下代码将图像绑定(bind)到 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 之间。
最佳答案
我终于解决了这个问题。 我认为问题在于获取全分辨率图像。
代替:
CGImageRef iref = [rep fullResolutionImage];
我用过:
CGImageRef iref = [myasset aspectRatioThumbnail];
一切正常。控制台没有错误,没有崩溃,但图像的质量/分辨率降低了。
关于ios - 加载照片库图像时发生错误 : ERROR: FigCreateCGImageFromJPEG returned -12910. 423114 字节。我们将退回到软件解码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14016879/