首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >正在获取照片alassetlibrary资产表示大小为零

正在获取照片alassetlibrary资产表示大小为零
EN

Stack Overflow用户
提问于 2012-08-02 14:31:26
回答 1查看 465关注 0票数 2

当我使用ALAssetLibrary获取照片时,对于一些图像,AssetRepresentation.size为零,这不会在我的ImageView上生成图像。代码如下:

代码语言:javascript
复制
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupAlbum usingBlock:^(ALAssetsGroup *group, BOOL *stop) {

    if ([[group valueForProperty:ALAssetsGroupPropertyName] isEqual:self.groupName]) {

        [group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop){
            //Get the asset type
            NSString *assetType = [result valueForProperty:ALAssetPropertyType];
            if ([assetType isEqualToString:ALAssetTypePhoto]) {
                NSLog(@"Photo Asset");
            }
            //Get URLs for the assets
            NSDictionary *assetURLs = [result valueForProperty:ALAssetPropertyURLs];

            NSUInteger assetCounter = 0;
            for (NSString *assetURLKey in assetURLs) {
                assetCounter++;
            }
            //Get the asset's representation object
            ALAssetRepresentation *assetRepresentation = [result defaultRepresentation];

            //From this asset representation, we take out data for image and show it using imageview.

            dispatch_async(dispatch_get_main_queue(), ^(void){
                CGImageRef imgRef = [assetRepresentation fullResolutionImage];
                //Img Construction
                UIImage *image = [[[UIImage alloc] initWithCGImage:imgRef] autorelease];

                NSLog(@"before %@:::%lld", [image description], [assetRepresentation size]); //Prints '0' for size

                if((image != nil)&& [assetRepresentation size] != 0){

                   //display in image view
                }
                else{
                    // NSLog(@"Failed to load the image.");
                }
            });

        }];
    }
}failureBlock:^(NSError *error){
    NSLog(@"Error retrieving photos: %@", error);
}];


[library release];

请帮帮忙。我在这里做错了什么?我该如何获取图像呢?

EN

回答 1

Stack Overflow用户

发布于 2012-08-20 12:26:07

我认为你发布assets库太早了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11772193

复制
相关文章

相似问题

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