使用库读取iphone相册中的图像
我正在尝试编写一个从相册中读取资产的方法。我正在使用ALAsset从所有相册中获取所有图像,我的问题是如何自定义此方法以从我的相册中读取图像使用库读取iphone相册中的图像,iphone,ios,objective-c,alassetslibrary,alasset,Iphone,Ios,Objective C,Alassetslibrary,Alasset,我正在尝试编写一个从相册中读取资产的方法。我正在使用ALAsset从所有相册中获取所有图像,我的问题是如何自定义此方法以从我的相册中读取图像 /** * 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
/**
* 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"); }];
}
如何使用documentdataPath加载资产当您调用
enumerateGroupsWithTypes
时,在块中检查资产组名称(valueForProperty:
)。然后,您可以只添加适当的资产组,而不是将所有资产组添加到assetGroups
列表中。文件夹?专辑不确定你的意思,因为你似乎把两种不同的东西混在一起了documentdataPath
与资产库无关……您不需要向上投票,您可以标记为正确(就在投票按钮下方)。