【问题标题】:Ipad Application how to get images from custom albumIpad 应用程序如何从自定义相册中获取图像
【发布时间】:2012-10-15 05:48:21
【问题描述】:

我正在开发一个 iPad 应用程序,其中我使用 This. 将图像保存到自定义相册中

现在我想从该自定义文件夹中获取所有图像,我需要在动画UIImageView 中显示所有这些图像。

我知道如何设置动画,但我想知道如何从特定的自定义文件夹中获取所有图像

【问题讨论】:

  • 只要接受用户给出的答案就可以访问这个link
  • 感谢您的回答,但是在此库中包含什么,如何获取数组中的所有图像,请逐步完成。
  • 好吧,对不起,我给了你错误的代码,它只给你号码和整张专辑:)
  • 查看我的 EDIT:1 代码可能会对您有所帮助

标签: ipad photos


【解决方案1】:

查看我用来从自定义相册加载图像的代码。我使用相同的示例代码将图像存储在自定义相册中。

NSMutableArray *tempArray = [[NSMutableArray alloc] init];
    self.assetGroups = tempArray;

    library = [[ALAssetsLibrary alloc] init];      

    // Load Albums into assetGroups

        // Group enumerator Block
        void (^assetGroupEnumerator)(ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop) 
        {
            if (group == nil) 
            {
                return;
            }
            if([[group valueForProperty:ALAssetsGroupPropertyName] isEqualToString:kAlbumName])
            {
                [self.assetGroups addObject:group];
                [self reloadTableView];
                return;
            }
        };

        // Group Enumerator Failure Block
        void (^assetGroupEnumberatorFailure)(NSError *) = ^(NSError *error) {

            CustomAlertView * alert = [[CustomAlertView alloc] initWithTitle:@"Error" message:[NSString stringWithFormat:@"Album Error: %@ - %@", [error localizedDescription], [error localizedRecoverySuggestion]] delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
            [alert show];

            NSLog(@"A problem occured %@", [error description]);                                     
        };  

        // Enumerate Albums
        [library enumerateGroupsWithTypes:ALAssetsGroupAll
                               usingBlock:assetGroupEnumerator 
                             failureBlock:assetGroupEnumberatorFailure];

这里的kAlbumName 是一个包含自定义专辑名称的字符串 ivar。

编辑:1

上面的代码只是为您提供了现在选择的所有照片的整个相册,以便使用以下代码从相册中获取这些照片

[self.assetGroup enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) 
     {         
         if(result == nil) 
             return;
     CGRect viewFrames = kThumbSize;//CGRectMake(0, 0, 75, 75);
         UIImageView *assetImageView = [[UIImageView alloc] initWithFrame:viewFrames];
        [assetImageView setContentMode:UIViewContentModeScaleToFill];
        [assetImageView setImage:[UIImage imageWithCGImage:(__bridge CGImageRef)([result originalAsset])]];
     }];

注意:不要将kThumbSize 定义为注释中的CGRectMake()

享受编码:) 快乐的一天:)

【讨论】:

  • 使用下面的链接我得到了一系列图像,它在模拟器中工作正常,但在设备中却没有,为什么? stackoverflow.com/questions/10040731/…
  • 在设备上运行应用程序时发生了什么?它是否给出任何错误或只是不显示任何图像?
  • 它不显示任何图像,它只是执行失败块并显示警告消息没有找到专辑
  • 这意味着代码中没有命名专辑,即如果您将MyAlbum作为专辑名称,则您的设备上没有该专辑名称 请检查您在代码中输入的名称和使用设备上的照片应用程序是否在您的设备上命名相册
  • 必须没有在您的设备上创建相册,因此代码无法找到代码中命名的相册仔细检查您的模拟器中的警报消息是否表明您已通过您的应用创建相册或手动。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-11-17
  • 2016-09-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-17
  • 1970-01-01
相关资源
最近更新 更多