gpt4 book ai didi

iphone - 使用 ALAssetsLibrary 从 iphone 相册中读取图像

转载 作者:可可西里 更新时间:2023-11-01 05:12:59 24 4
gpt4 key购买 nike

我正在尝试编写一种从相册中读取 Assets 的方法我正在使用 ALAsset 从所有相册中获取所有图像,我的问题是如何自定义此方法以从 myAlbum 中读取图像

/**
* 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 时,在 block 中检查 Assets 组名称 (valueForProperty:)。然后,无需将所有 Assets 组添加到您的 assetGroups 列表中,您可以只添加适当的 Assets 组。

关于iphone - 使用 ALAssetsLibrary 从 iphone 相册中读取图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19297396/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com