iOS獲取手機裏的照片

    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];

    

    [library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) {

        

        if(group != nil){

            

            [group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {

                

                if(result != nil){

                    

                    //獲取資源的類型

                    NSString *type = [result valueForProperty:ALAssetPropertyType];

                    if([type isEqualToString:ALAssetTypePhoto]){//照片

                        

                        //獲取縮略圖

                        CGImageRef thumbCGImage = [result thumbnail];

                        UIImage *thumImage = [UIImage imageWithCGImage:thumbCGImage];

                        

                        //獲取原圖

                        ALAssetRepresentation *representation = [result defaultRepresentation];

                        CGImageRef fullCGImage = [representation fullResolutionImage];

                        UIImage *fullImage = [UIImage imageWithCGImage:fullCGImage];

                    }else if([type isEqualToString:ALAssetTypeVideo]){//視頻

                        

                         ALAssetRepresentation *representation = [result defaultRepresentation];

                        NSURL *url = [representation url];

                        //播放視頻

                    }

                }

            }];

        }

        

    } failureBlock:^(NSError *error) {

        NSLog(@"遍歷錯誤");

    }];


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章