原文地址:http://stackoverflow.com/questions/9766394/get-exif-data-from-uiimage-uiimagepickercontroller

ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library assetForURL:[info objectForKey:UIImagePickerControllerReferenceURL]resultBlock:^(ALAsset *asset) {ALAssetRepresentation *image_representation = [asset defaultRepresentation];// create a buffer to hold image datauint8_t *buffer = (Byte*)malloc(image_representation.size);NSUInteger length = [image_representation getBytes:buffer fromOffset: 0.0  length:image_representation.size error:nil];if (length != 0)  {// buffer -> NSData object; free buffer afterwardsNSData *adata = [[NSData alloc] initWithBytesNoCopy:buffer length:image_representation.size freeWhenDone:YES];// identify image type (jpeg, png, RAW file, ...) using UTI hintNSDictionary* sourceOptionsDict = [NSDictionary dictionaryWithObjectsAndKeys:(id)[image_representation UTI] ,kCGImageSourceTypeIdentifierHint,nil];// create CGImageSource with NSDataCGImageSourceRef sourceRef = CGImageSourceCreateWithData((__bridge CFDataRef) adata,  (__bridge CFDictionaryRef) sourceOptionsDict);// get imagePropertiesDictionary
                 CFDictionaryRef imagePropertiesDictionary;imagePropertiesDictionary = CGImageSourceCopyPropertiesAtIndex(sourceRef,0, NULL);// get exif dataCFDictionaryRef exif = (CFDictionaryRef)CFDictionaryGetValue(imagePropertiesDictionary, kCGImagePropertyExifDictionary);NSDictionary *exif_dict = (__bridge NSDictionary*)exif;NSLog(@"exif_dict: %@",exif_dict);// save image WITH meta dataNSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];NSURL *fileURL = nil;CGImageRef imageRef = CGImageSourceCreateImageAtIndex(sourceRef, 0, imagePropertiesDictionary);if (![[sourceOptionsDict objectForKey:@"kCGImageSourceTypeIdentifierHint"] isEqualToString:@"public.tiff"]){fileURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@.%@",documentsDirectory,@"myimage",[[[sourceOptionsDict objectForKey:@"kCGImageSourceTypeIdentifierHint"] componentsSeparatedByString:@"."] objectAtIndex:1]]];CGImageDestinationRef dr = CGImageDestinationCreateWithURL ((__bridge CFURLRef)fileURL,(__bridge CFStringRef)[sourceOptionsDict objectForKey:@"kCGImageSourceTypeIdentifierHint"],1,NULL);CGImageDestinationAddImage(dr, imageRef, imagePropertiesDictionary);CGImageDestinationFinalize(dr);CFRelease(dr);}else{NSLog(@"no valid kCGImageSourceTypeIdentifierHint found …");}// clean up
                 CFRelease(imageRef);CFRelease(imagePropertiesDictionary);CFRelease(sourceRef);}else {NSLog(@"image_representation buffer length == 0");}}failureBlock:^(NSError *error) {NSLog(@"couldn't get asset: %@", error);}];

转载于:https://www.cnblogs.com/Walking-Jin/p/7160418.html

ALAsset 将资源转换为 NSData相关推荐

  1. UIImage存为本地文件与UIImage转换为NSData

    UIImage *image=@"XXX"; //png格式 NSData *imagedata=UIImagePNGRepresentation(image); //JEPG格式 ...

  2. 资源论文非系统论文,NLP 圈同行评审存在的六大固化误区!

    来源:AI科技评论 本文约5500字,建议阅读10+分钟 苹果是苹果,橘子是橘子,两者都有自己的优点. NLP中的大多数成功案例都是关于监督学习或半监督学习的.从根本上说,这意味着我们的解析器.情感分 ...

  3. Objective-C 中Socket常用转换机制(NSData,NSString,int,Uint8,Uint16,Uint32,byte[])

    最近项目中要用到socket通讯,由于涉及到组包问题,所以需要数据类型之间的来回转换,现在分享出来 如果想要请教Socket的问题请留言,我会随时回答的 1. int类型转16进制hexstring ...

  4. php灰度化,PHP Imagick – 将图像转换为灰度(非常糟糕的结果)

    我正在用 PHP进行一些图像编辑,因为GD提供的功能较少,我切换到了Imagick. 其中一个过程是灰度图像.一切顺利(在Windows 7本地,Imagick 2.2.1-dev 6.5.8-7 Q ...

  5. iOS - Swift NSData 数据

    本文目录 前言 1.NSData 的创建 2.数据的长度 3.数据的获取 4.NSData 的比较 5.NSData 的存储 6.NSData 与 字符串 的相互转换 7.NSData 与 Base6 ...

  6. Iphone开发-NSdata 与 NSString,Byte数组,UIImage 的相互转换

    原文摘自:NSdata转化为int 1. NSData 与 NSString NSData-> NSString NSString *aString = [[NSString alloc] in ...

  7. amazon php 空间,如何将PHP图像资源放入Amazon Web Services?

    我目前正在构建一个Zend Framework PHP Web服务,它将从Android手机上传的图像调整大小,并将其放入Amazon Web Services S3. 这是我的代码: $img = ...

  8. php 字符串放到数组中,在PHP中将字符串转换为数组(Converting string into array in php)...

    在PHP中将字符串转换为数组(Converting string into array in php) 我有像下面的字符串 ["Day1"]["Morning" ...

  9. 将VC++黑白屏蔽图转换为Cocos2dx中可用的png

    突然想将Windows 2d游戏中现成的游戏资源转换为Cocos2d中可用的Png图片 但老的windows游戏中都不采用带有Alpha通道的bitmap图片 因此在BitBlt中要用两个图片实现透明 ...

最新文章

  1. Google protobuf使用技巧和经验
  2. 数据库实现列值合并为行
  3. msp430项目编程53
  4. FreeBSD长模式不兼容
  5. 【Recorder.js+百度语音识别】全栈方案技术细节
  6. 第三十讲:Android之Animation(五)
  7. 听同事讲 Bayesian statistics: Part 1 - Bayesian vs. Frequentist
  8. checkbox取反
  9. 云原生日志管理瑞士军刀 Fluent Operator 中文入门教程
  10. CentOS6.5修改系统语言为英语
  11. 二次规划(QP)求解与序列二次规划(SQP)求解非线性规划问题
  12. python灰色预测模型_GM(1,n)(灰色模型代码)
  13. 数学建模(三)SARS的传播(03年A题)
  14. 孩子给产品经理的一堂课
  15. vue返回首页后如何清空路由
  16. 阿里云推出高效病毒基因序列检索功能,它的底层逻辑原来是这样的
  17. Elastic 7.14.0 版推出业界首个免费开放的 Limitless XDR
  18. Unity3D学习笔记(6)—— 飞碟射击游戏
  19. matlab函数merge_MATLAB数据合并方法
  20. 总结 nginx access.log 太大如何清理

热门文章

  1. Odoo10参考系列--QWeb报表
  2. 台达vfd一ⅴe变频说明书_PLC运动控制实例解析:PLC与变频器系统
  3. metal分析是什么意思_变压器原理是什么?容量是什么意思?电力工程技术专家精讲分析...
  4. adb 查看屏幕大小_蚂蚁森林自动收取能量、偷取能量、浇水(使用adb、python)...
  5. hashmap头插法和尾插法区别_Java程序员必知:HashMap进行put操作会不会引起死循
  6. linux ftp远程更新,用ftp远程安装linux
  7. 单机 mysql 复制_MySQL单机复制
  8. python可视化工具bokeh_浅谈python可视化包Bokeh
  9. c语言输入一串数字存入数组_在Excel中快速输入,竟是输入一串数字?
  10. 对10亿个数据去重java_JAVA 8 新特性