[英]Trying to retrieve a set of photos using ALAssetsLibrary
我目前正在開發實現人臉檢測和標記的iPhone應用程序。 我正在使用SQLite數據庫存儲標簽和相應圖像的url。 現在,在檢索的同時,我將實現一些邏輯以基於標簽過濾出所需的圖像,並獲取與該標簽匹配的圖像URL集(來自Db)。 (格式為-assess-library://asset/asset.JPG?id = 79465E8C-53B9-40D6-B11C-07A1856E9093&ext = JPG的資產庫URL)
我的問題是,如果我有一個NSURL數組,如何使用ALAssetsLibrary加載僅包含數組中URL而不包含默認圖片庫中所有圖像的自定義圖像選擇器?
我已經閱讀了如何根據以下答案從URL加載圖像: https : //stackoverflow.com/a/18888938
針對以下問題: 顯示從iPhone中的ALAsset檢索的URL中獲取圖像
如何在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.