我使用下面的代码从相机卷中加载图像。但是当图像在uiimageview中显示时,图像有时会向左旋转90度。我该怎么纠正呢?谢谢!
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
{
ALAssetRepresentation *rep = [myasset defaultRepresentation];
CGImageRef iref = [rep fullResolutionImage];
if (iref) {
cell.image.image = [UIImage imageWithCGImage:iref];
}
};
ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror)
{
NSLog(@"Can't get image - %@",[myerror localizedDescription]);
};
NSString *urlString = [[_alleArtikel objectAtIndex:indexPath.row] bildURL];
NSURL *asseturl = [NSURL URLWithString:urlString];
ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
[assetslibrary assetForURL:asseturl
resultBlock:resultblock
failureBlock:failureblock];更新:
使用解决方案时:
dispatch_async(dispatch_get_main_queue(), ^{
cell.image.image = [UIImage imageWithCGImage:iref scale:[rep scale] orientation:(UIImageOrientation)[rep orientation]];
});应用程序崩溃,我得到以下错误:
invalid attempt to access <ALAssetRepresentationPrivate: 0x176a3350> past the lifetime of its owning ALAssetsLibrary我应该说,我正在使用cellForItemAtIndexPath方法中的代码。
更新2:
我能够通过在更新ui时不使用主队列来避免错误。我这里有一个小的边节点,上面的代码正在为给定的单元加载错误的图像。很奇怪。
发布于 2013-12-20 10:48:55
您必须将您的方法编辑为
if (iref) {
dispatch_async(dispatch_get_main_queue(), ^{
cell.image.image = [UIImage imageWithCGImage:iref scale:[rep scale] orientation:(UIImageOrientation)[rep orientation]];
});
}上面的代码将检索带有捕获/原始方向的资产映像。
您必须更新主线程上的用户界面,以获得更好的性能。所以你必须用任何一个
dispatch_async(dispatch_get_main_queue()或
performSelectorOnMainThreadhttps://stackoverflow.com/questions/20689538
复制相似问题