使用元数据(EXIF 数据)将 NSData 转换为 UIImage



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

我尝试了这两种转换:

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

我已经做了我的研究,发现每当NSData转换为UIImage反之亦然时,元数据(EXIF 数据)都会丢失。我如何转换以使我的元在两次转换中退出,即NSData UIImage,反之亦然

非常感谢帮助

试试这段代码

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

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];

最新更新