标签:style blog http color io os ar for sp
今天一直在弄这个东西,各种度,网上有不少这样的例子和讲解,但是就是没有正常获取出来。。很郁闷!
后来终于各种尝试,为了让小伙伴们少折腾会,特写出此简单的类。
技术能力有限,多有不足,还请多多指教!
简单类快捷入口:
链接: http://pan.baidu.com/s/1hqvJLru 密码: 1jd0
//出处:http://www.cnblogs.com/madordie/ // // 声明:写此类时候只为了获取图库中的图片。由于真机不在手边,只在模拟器上测试(iOS7.1) // 如需要获得其他视频之类的可以自行更改fillAssetGroups函数 // // // 本地照片管理 // (单例模式) // 用法: //JGPhotoAlbumManager *manager = [JGPhotoAlbumManager shared]; //[manager setSaveAllPhotos:^(NSArray *images) { // if (!_tableData) { // _tableData = [[NSMutableArray alloc] init]; // } // [_tableData removeAllObjects]; // [_tableData addObjectsFromArray:images]; // [_tableView reloadData]; //}]; // // cell 填充: //ALAsset *asset = _tableData[indexPath.row]; //[cell.imageView setImage:[asset fastGetThumbnailImage]]; //注: //fastGetThumbnailImage为自定义类别,见#import "ALAsset+JGFastGetPhoto.h" //
关键代码:
//如果需要获取别的更改下面的addObject位置 #pragma mark - 填充 _assetGroups - (void)fillAssetGroups { ALAssetsLibrary *assetsLibrary = [JGPhotoAlbumManager sharedAssetsLibrary];//生成整个photolibrary句柄的实例 [assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {//获取所有group if (group) { [group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {//从group里面 NSString* assetType = [result valueForProperty:ALAssetPropertyType]; if ([assetType isEqualToString:ALAssetTypePhoto]) { NSLog(@"Photo"); [_assetGroups addObject:result]; }else if([assetType isEqualToString:ALAssetTypeVideo]){ NSLog(@"Video"); }else if([assetType isEqualToString:ALAssetTypeUnknown]){ NSLog(@"Unknow AssetType"); } NSDictionary *assetUrls = [result valueForProperty:ALAssetPropertyURLs]; NSUInteger assetCounter = 0; for (NSString *assetURLKey in assetUrls) { NSLog(@"Asset URL %lu = %@",(unsigned long)assetCounter,[assetUrls objectForKey:assetURLKey]); } NSLog(@"Representation Size = %lld",[[result defaultRepresentation]size]); }]; } else { //stop dispatch_async(dispatch_get_main_queue(), ^(void) { _saveAllPhotos(_assetGroups); }); } } failureBlock:^(NSError *error) { NSLog(@"Enumerate the asset groups failed."); }]; }
@interface ALAsset (JGFastGetPhoto) //图片URL - (NSString *)fastGetURLString; - (NSURL *)fastGetURL; //缩略图 - (UIImage *)fastGetThumbnailImage; //全屏图 - (UIImage *)fastGetFullScreenImage; //高清图 - (UIImage *)fastGetFullResolutionImage; //获取时间 - (NSString *)fastGetDataString; //缩略图 - (UIImage *)fastGetThumbnailImage { CGImageRef ref = [self thumbnail]; return [UIImage imageWithCGImage:ref]; }
标签:style blog http color io os ar for sp
原文地址:http://www.cnblogs.com/madordie/p/4032200.html