OGeek|极客世界-中国程序员成长平台

标题: ios - 使用元数据(EXIF 数据)将 NSData 转换为 UIImage [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 18:30
标题: ios - 使用元数据(EXIF 数据)将 NSData 转换为 UIImage

我的 NSData 包含从外部硬件获取的图像具有元数据。我已通过将图像上传到 AWS 对其进行了测试。

我已经尝试了这两种转换:

UIImage *image = [UIImage imageWithData:_downloadedImageData ];

UIImage *image = [[UIImage alloc] initWithData:_downloadedImageData];

我进行了研究,发现只要将 NSData 转换为 UIImage 或反之,元数据(EXIF 数据)就会丢失。如何进行转换,以使我的元在两种转换中都退出,即 NSDataUIImage 反之亦然

帮助非常感谢



Best Answer-推荐答案


试试这个代码

创建保存图像数据的路径。

NSArray *pathArr = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, 
                                                   NSUserDomainMask,
                                                   YES);
NSString *path = [[pathArr objectAtIndex:0]
              stringByAppendingPathComponent"_downloadedImageData.data" ];

检索保存的数据

NSData *retrievedData = [NSData dataWithContentsOfFile:path];
UIImageView *img = [[UIImageView alloc] 
                  initWithFrame:CGRectMake(100, 100, 200, 200)];
img.image = [UIImage imageWithData:retrievedData];
[self.view addSubview:img];

关于ios - 使用元数据(EXIF 数据)将 NSData 转换为 UIImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41498128/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4