首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ALAssetsLibrary图像扭曲

ALAssetsLibrary图像扭曲
EN

Stack Overflow用户
提问于 2013-12-19 18:56:16
回答 1查看 385关注 0票数 0

我使用下面的代码从相机卷中加载图像。但是当图像在uiimageview中显示时,图像有时会向左旋转90度。我该怎么纠正呢?谢谢!

代码语言:javascript
复制
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];

更新:

使用解决方案时:

代码语言:javascript
复制
            dispatch_async(dispatch_get_main_queue(), ^{
                cell.image.image =  [UIImage imageWithCGImage:iref scale:[rep scale] orientation:(UIImageOrientation)[rep orientation]];
            });

应用程序崩溃,我得到以下错误:

代码语言:javascript
复制
invalid attempt to access <ALAssetRepresentationPrivate: 0x176a3350> past the lifetime of its owning ALAssetsLibrary

我应该说,我正在使用cellForItemAtIndexPath方法中的代码。

更新2:

我能够通过在更新ui时不使用主队列来避免错误。我这里有一个小的边节点,上面的代码正在为给定的单元加载错误的图像。很奇怪。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-12-20 10:48:55

您必须将您的方法编辑为

代码语言:javascript
复制
if (iref) {

  dispatch_async(dispatch_get_main_queue(), ^{

       cell.image.image =  [UIImage imageWithCGImage:iref scale:[rep scale] orientation:(UIImageOrientation)[rep orientation]];
  });
}

上面的代码将检索带有捕获/原始方向的资产映像。

您必须更新主线程上的用户界面,以获得更好的性能。所以你必须用任何一个

代码语言:javascript
复制
dispatch_async(dispatch_get_main_queue()

代码语言:javascript
复制
performSelectorOnMainThread
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20689538

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档