【问题标题】:Trying to retrieve a set of photos using ALAssetsLibrary尝试使用 ALAssetsLibrary 检索一组照片
【发布时间】:2013-11-25 07:38:41
【问题描述】:

我目前正在开发一个实现人脸检测和标记的 iPhone 应用程序。我正在使用 SQLite 数据库来存储标签和相应图像的 url。现在,在检索时,我将实现一些逻辑以根据标签过滤掉所需的图像,并获取与该标签匹配的图像 URL 集(来自 Db)。 (资产库 URL 的形式 - assets-library://asset/asset.JPG?id=79465E8C-53B9-40D6-B11C-07A1856E9093&ext=JPG)

我的问题是,如果我有一个 NSURL 数组,如何使用 ALAssetsLibrary 加载自定义图像选择器,数组中只有 URL,而不是默认照片库中的所有图像?

我已经阅读了如何根据这个答案从 URL 加载图像: https://stackoverflow.com/a/18888938

对于这个问题: display image from URL retrieved from ALAsset in iPhone

如何在我的 URL 数组上运行单个循环以使用 ALAsset 将这些图像加载到自定义 UICollectionView 中以复制 ImagePickerController?

【问题讨论】:

  • 你如何尝试使用你已经找到的代码?

标签: ios iphone alassetslibrary photo-tagging


【解决方案1】:

看看这个来自苹果的sample code 来实现一个自定义图像选择器。

【讨论】:

    【解决方案2】:
    /**
     *  This method is used to get all images from myAlbum 
     *  folder in device if getAlbumImages is set to 1
     *  else loads all images from devices library
     */
    -(void)readImages:(int)getAlbumImages
    {
        imageArray = [[NSArray alloc] init];
        mutableArray =[[NSMutableArray alloc]init];
        NSMutableArray* assetURLDictionaries = [[NSMutableArray alloc] init];
    
        library = [[ALAssetsLibrary alloc] init];
    
        if(getFolderImages == 1) {
            // Load images from Shareaflash folder
            NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
            NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder
            NSString *documentdataPath = [documentsDirectory stringByAppendingPathComponent:@"myFolder"];
            NSLog(@"documentdataPath %@",documentdataPath);
    
        } else {
            // Load all images
        }
    
        void (^assetEnumerator)( ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop) {
            if(result != nil) {
                if([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypePhoto]) {
                    [assetURLDictionaries addObject:[result valueForProperty:ALAssetPropertyURLs]];
    
                    NSURL *url = (NSURL*) [[result defaultRepresentation]url];
    
                    [library assetForURL:url resultBlock:^(ALAsset *asset) {
                                 [mutableArray addObject:asset];
    
                                 if ([mutableArray count]==count)
                                 {
                                     imageArray =[[NSArray alloc] initWithArray:mutableArray];
                                     [self allPhotosCollected:imageArray];
                                 }
                             }
                            failureBlock:^(NSError *error){ NSLog(@"operation was not successfull!"); } ];
                }
            }
        };
        NSMutableArray *assetGroups = [[NSMutableArray alloc] init];
    
        void (^ assetGroupEnumerator) ( ALAssetsGroup *, BOOL *)= ^(ALAssetsGroup *group, BOOL *stop) {
            if(group != nil) {
                [group enumerateAssetsUsingBlock:assetEnumerator];
                [assetGroups addObject:group];
                count=[group numberOfAssets];
            }
        };
        assetGroups = [[NSMutableArray alloc] init];
    
        [library enumerateGroupsWithTypes:ALAssetsGroupAll
                             usingBlock:assetGroupEnumerator
                             failureBlock:^(NSError *error) { NSLog(@"There is an error"); }];
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多