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