我有ViewController1ViewController2ViewController1UICollectionView,它使用ASAssetLibrary将缩略图加载到UICollectionViewCell中:

NSMutableArray *collector = [[NSMutableArray alloc] initWithCapacity:0];
ALAssetsLibrary *al = [TemplateEditBarController defaultAssetsLibrary];
[al enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos
                  usingBlock:^(ALAssetsGroup *group, BOOL *stop)
 {
     [group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop)
      {
          if (asset) {
              [collector addObject:asset];
          }
      }];
     assetsarray = collector;//<--assetsarray is local.
 }
                failureBlock:^(NSError *error) { NSLog(@"fail!");}
 ];

选择cell时,我想将NSStringNSURL传递给ViewController2,以便它将调用并显示全分辨率图像。但是当NSLog网址时:
ALAsset* asset = backgroundsarray[row];
    ALAssetRepresentation *representation = [asset defaultRepresentation];
    NSURL *url = [representation url];
    newbg = [url absoluteString];//<-NSLog this.

我得到:

asset-library://asset/asset.JPG?id = 6E5438ED-9A8C-4ED0-9DEA-AB2D8F8A9360&ext = JPG

我尝试更改为得到的[url path]:

asset.JPG

如何获取实际的照片网址,以便可以转换为NSString并传递给ViewController2

最佳答案

NSURL* aURL = [NSURL URLWithString:imagePath];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library assetForURL:aURL resultBlock:^(ALAsset *asset)
     {
         UIImage  *image = [UIImage imageWithCGImage:[[asset defaultRepresentation] fullScreenImage] scale:0.5 orientation:UIImageOrientationUp];
         imageView.image=image;

     }
            failureBlock:^(NSError *error)
     {
         // error handling
         NSLog(@"failure-----");
     }];

关于ios - iOS-显示来自“ALAssetLibrary”的图片,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30205554/

10-13 03:59