简体   繁体   中英

Convert NSData to UIImage with metadata (EXIF data)

My NSData which contains an image taken from an external hardware has metadata.. I have tested it by uploading the image to AWS.

I have tried these two conversions:

UIImage *image = [UIImage imageWithData:_downloadedImageData ];

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

I have done my research and found out whenever NSData is converted to UIImage or vice versa the metadata (EXIF data) is lost. How do I convert such that my meta exits in both conversion ie NSData to UIImage and vice versa

Help much appreciated

Try this code

create path to save the image data.

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

retrieving the saved 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];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM