[原]iOS7.1擷取圖庫所有照片的方法封裝

來源:互聯網
上載者:User

標籤: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擷取圖庫所有照片的方法封裝

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.