Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS-显示来自“ALAssetLibrary”的图像`_Ios_Objective C_Iphone - Fatal编程技术网

iOS-显示来自“ALAssetLibrary”的图像`

iOS-显示来自“ALAssetLibrary”的图像`,ios,objective-c,iphone,Ios,Objective C,Iphone,我有ViewController1和ViewController2。 ViewController1是UICollectionView,它使用ASAssetLibrary将缩略图加载到UICollectionViewCell: NSMutableArray *collector = [[NSMutableArray alloc] initWithCapacity:0]; ALAssetsLibrary *al = [TemplateEditBarController defaultAssetsL

我有
ViewController1
ViewController2
ViewController1
UICollectionView
,它使用
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!");}
 ];
我得到:

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

我尝试更改为
[url路径]
我得到:

asset.JPG


如何获取实际的照片url,以便我可以转换为
NSString
以传递到
ViewController2

显然除了传递
ALAsset
之外,没有任何直接的解决方案。我就是这么做的:

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-----");
     }];
ViewController1
中,即
UICollectionViewController
,我具有以下功能:

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
//NSLog(@"selected row: %ld",(long)indexPath.row);
long row = [indexPath row];
NSString* newbg = [[NSString alloc]init];
if ([bartype isEqualToString:@"photolibrary"]) {
    ALAsset* asset = backgroundsarray[row];
    [_delegate changeBackgroundWithAsset:asset];
}

然后我在
ViewController2
中有一个函数来处理
ALAsset

-(void)changeBackgroundWithAsset:(ALAsset*)b{
ALAssetRepresentation *rep = [b defaultRepresentation];
CGImageRef iref = [rep fullResolutionImage];
UIImage *bimage;
bimage = [UIImage imageWithCGImage:iref];
UIImageView* bgview = [[UIImageView alloc]init];
bgview = curbgview;
bgview.image = bimage;
}我的解决方案如下:

ALAssetsLibrary *assetslibrary = [[ALAssetsLibrary alloc] init];
[assetslibrary assetForURL:assetURL resultBlock:^(ALAsset *asset) {
    if (asset) {
       image = [UIImage imageWithCGImage:[asset aspectRatioThumbnail]];
    }
}

查看URL,但我不知道为什么加载的图像的分辨率不是完整的。
ALAssetsLibrary *assetslibrary = [[ALAssetsLibrary alloc] init];
[assetslibrary assetForURL:assetURL resultBlock:^(ALAsset *asset) {
    if (asset) {
       image = [UIImage imageWithCGImage:[asset aspectRatioThumbnail]];
    }
}