1. 程式人生 > >iOS-使用ALAssetsLibrary獲取相冊圖片視頻

iOS-使用ALAssetsLibrary獲取相冊圖片視頻

rip att top round enumerate ets log sets image

直接上代碼:

ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
    
    [library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos
                           usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
                               
                               // Filter down to only photos
[group setAssetsFilter:[ALAssetsFilter allPhotos]]; // Grab the first photo return [group enumerateAssetsAtIndexes:[NSIndexSet indexSetWithIndex:0] options:
0 usingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) { if (result) {
id repressentation = [result defaultRepresentation]; // 可以生產一個AVAsset NSURL *url = [repressentation url]; AVAsset *asset = [AVAsset assetWithURL:url]; // 也可以直接獲取image self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageWithCGImage:[repressentation fullResolutionImage]]]; } }]; } failureBlock:^(NSError *error) { NSLog(@"Error: %@", [error localizedDescription]); }];

iOS-使用ALAssetsLibrary獲取相冊圖片視頻