iOS获取手机里的照片

来源:互联网 发布:玻璃幕墙设计软件 编辑:程序博客网 时间:2024/06/11 04:06

    ALAssetsLibrary *library = [[ALAssetsLibraryalloc] init];

    

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

        

       if(group != nil){

            

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

                

               if(result != nil){

                    

                   //获取资源的类型

                   NSString *type = [result valueForProperty:ALAssetPropertyType];

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

                        

                       //获取缩略图

                       CGImageRef thumbCGImage = [result thumbnail];

                       UIImage *thumImage = [UIImageimageWithCGImage:thumbCGImage];

                        

                       //获取原图

                       ALAssetRepresentation *representation = [resultdefaultRepresentation];

                       CGImageRef fullCGImage = [representation fullResolutionImage];

                       UIImage *fullImage = [UIImageimageWithCGImage:fullCGImage];

                    }elseif([type isEqualToString:ALAssetTypeVideo]){//视频

                        

                        ALAssetRepresentation *representation = [resultdefaultRepresentation];

                       NSURL *url = [representation url];

                       //播放视频

                    }

                }

            }];

        }

        

    }failureBlock:^(NSError *error) {

       NSLog(@"遍历错误");

    }];


0 0
原创粉丝点击