如何使用ALAsseetLibrary显示图像

时间:2016-04-08 06:48:18

标签: ios objective-c uiimage alassetslibrary

我正在使用ALAssetLibrary访问图像列表,我得到了日志文件中所有图像的列表。但我无法显示任何图像。任何人都可以帮我解决这个问题吗?

要获取所有图像的列表,我的代码就在这里---

- (IBAction)getListOfImages:(id)sender {

NSMutableArray* assetURLDictionaries = [[NSMutableArray alloc] init];
NSMutableArray *xy =[[NSMutableArray alloc]init];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];

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]];

            NSLog(@"result is:%@",result);
            NSLog(@"asset URLDictionary is:%@",assetURLDictionaries);
            NSURL *url= (NSURL*) [[result defaultRepresentation]url];

            [library assetForURL:url
                     resultBlock:^(ALAsset *asset) {
                         [xy addObject:[UIImage imageWithCGImage:[[asset defaultRepresentation] fullScreenImage]]];
                         NSLog(@" xy is:%@",xy);
                         UIImageView *image =[ [UIImageView alloc ] initWithImage:[xy objectAtIndex:0]];
                         NSLog(@"image is:%@",image);
                     }
                    failureBlock:^(NSError *error){ NSLog(@"test:Fail"); } ];
        }
    }
};

NSMutableArray *assetGroups = [[NSMutableArray alloc] init];
void (^ assetGroupEnumerator) ( ALAssetsGroup *, BOOL *)= ^(ALAssetsGroup *group, BOOL *stop) {
    NSLog(@"hello");
    if(group != nil) {
        [group enumerateAssetsUsingBlock:assetEnumerator];
        [assetGroups addObject:group];
        NSLog(@"Number of assets in group :%d",[group numberOfAssets]);
        NSLog(@"asset group is:%@",assetGroups);
    }
};

assetGroups = [[NSMutableArray alloc] init];

[library enumerateGroupsWithTypes:ALAssetsGroupAll
                       usingBlock:assetGroupEnumerator
                     failureBlock:^(NSError *error) {
                         NSLog(@"A problem occurred");
                     }];
}

0 个答案:

没有答案