Reputation: 97
I am currently developing an iPhone application that implements face detection and tagging. I am using the SQLite database to store the tags and the url of corresponding images. 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. (Asset Library URL's of the form - assets-library://asset/asset.JPG?id=79465E8C-53B9-40D6-B11C-07A1856E9093&ext=JPG)
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?
I have read how to load an image from a URL based on this answer: https://stackoverflow.com/a/18888938
for this question: display image from URL retrieved from ALAsset in iPhone
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?
Upvotes: 0
Views: 1317
Reputation: 3831
/**
* 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"); }];
}
Upvotes: 0
Reputation: 1997
Have a look on this sample code from apple to implement a custom image picker.
Upvotes: 0