获取照片的属性信息

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/like7xiaoben/article/details/10157591
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    //获取图片的NSURL 来源于AssetsLibrary.framework  #import <AssetsLibrary/AssetsLibrary.h>
    NSURL *url = [info objectForKey:UIImagePickerControllerReferenceURL];
    
    //ALAssetsLibrary 获取图片和视频
    ALAssetsLibrary *library = [[ALAssetsLibrary alloc]init];
    
    //根据url获取指定的图片  如果获取到了资源执行resultBlock,否则执行failureBlock
    //ALAsset实例 代表一个图片或者视频
    [library assetForURL:url resultBlock:^(ALAsset *asset){
        //defaultRepresentation 获取资源文件的默认属性
        //metadata 获取数据的数据,就是在默认属性中的数据,称之为元数据
        NSDictionary *imageData = [[NSMutableDictionary alloc]initWithDictionary:asset.defaultRepresentation.metadata];
        //kCGImagePropertyGPSDictionary 关于GPS的字典数据  来源于ImageIO.framework  #import <ImageIO/ImageIO.h>
        NSDictionary *gpsData = [imageData objectForKey:(NSString *)kCGImagePropertyGPSDictionary];
        //打印纬度
        NSLog(@"%@",[gpsData objectForKey:@"Altitude"]);
    }failureBlock:^(NSError *error){
        NSLog(@"error:%@",error);
    }];
}

阅读更多 登录后自动展开
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页