Ipad应用程序如何从自定义相册中获取图像
我正在开发一个iPad应用程序,其中我使用 现在,我想从该自定义文件夹中获取所有图像,并需要在动画Ipad应用程序如何从自定义相册中获取图像,ipad,photos,Ipad,Photos,我正在开发一个iPad应用程序,其中我使用 现在,我想从该自定义文件夹中获取所有图像,并需要在动画UIImageView中显示所有这些图像 我知道如何设置动画,但我想知道如何从特定的自定义文件夹中获取所有图像。请参见我用来从自定义相册中加载图像的代码。我使用相同的示例代码将图像存储在自定义相册中 NSMutableArray *tempArray = [[NSMutableArray alloc] init]; self.assetGroups = tempArray; lib
UIImageView
中显示所有这些图像
我知道如何设置动画,但我想知道如何从特定的自定义文件夹中获取所有图像。请参见我用来从自定义相册中加载图像的代码。我使用相同的示例代码将图像存储在自定义相册中
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
上面的代码只提供了所选的整个相册以及所有it照片。要从相册中获取这些照片,请使用以下代码
[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()
享受编码:)
快乐日:)只需接受用户给出的答案,只需访问此网站,感谢您的回答,但在这里,库包含什么,如何获取阵列中的所有图像,请给我一步一步来完成。好的,对不起,我给了你错误的代码,它只给了你号码和整个相册:)看我的编辑:1代码这可能会帮助你使用下面的链接我得到了一组图像它在模拟器中工作正常,但在设备中没有为什么?在设备上运行应用程序时会发生什么?它是否有任何错误或只是没有显示任何图像?它没有显示任何图像,它只是执行故障块并显示警告消息No album Found,这意味着代码中没有指定的相册,即如果您将
MyAlbum
作为相册名称,则指定的相册不在您的设备上。请使用设备上的照片应用程序检查您在代码中输入的名称以及设备上是否有指定的相册必须没有在您的设备上创建相册,因此代码无法找到代码中命名的相册。请仔细检查模拟器中的警告消息是否表明您已通过应用程序或手动创建相册。