標籤: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];}轉換
[原]iOS7.1擷取圖庫所有照片的方法封裝