[英]Trying to retrieve a set of photos using ALAssetsLibrary
I am currently developing an iPhone application that implements face detection and tagging. 我目前正在开发实现人脸检测和标记的iPhone应用程序。 I am using the SQLite database to store the tags and the url of corresponding images.
我正在使用SQLite数据库存储标签和相应图像的url。 Now, while retrieving I will be implementing some logic to filter out the desired images based on the tag and getting the set of URLs of images(from the Db) that match this tag.
现在,在检索的同时,我将实现一些逻辑以基于标签过滤出所需的图像,并获取与该标签匹配的图像URL集(来自Db)。 (Asset Library URL's of the form - assets-library://asset/asset.JPG?id=79465E8C-53B9-40D6-B11C-07A1856E9093&ext=JPG)
(格式为-assess-library://asset/asset.JPG?id = 79465E8C-53B9-40D6-B11C-07A1856E9093&ext = JPG的资产库URL)
My question is, if I have an array of NSURL's, how do I load a custom image picker using ALAssetsLibrary with only the URL's present in the array and not all the images from the default photo library? 我的问题是,如果我有一个NSURL数组,如何使用ALAssetsLibrary加载仅包含数组中URL而不包含默认图片库中所有图像的自定义图像选择器?
I have read how to load an image from a URL based on this answer: https://stackoverflow.com/a/18888938 我已经阅读了如何根据以下答案从URL加载图像: https : //stackoverflow.com/a/18888938
for this question: display image from URL retrieved from ALAsset in iPhone 针对以下问题: 显示从iPhone中的ALAsset检索的URL中获取图像
How do I run a single loop over my array of URL's to load these images using ALAssets into a custom UICollectionView to replicate the ImagePickerController? 如何在URL数组上运行一个循环,以使用ALAssets将这些图像加载到自定义UICollectionView中以复制ImagePickerController?
看一下苹果提供的示例代码 ,以实现自定义图像选择器。
/**
* 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"); }];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.