簡體   English   中英

使用元數據(EXIF數據)將NSData轉換為UIImage

[英]Convert NSData to UIImage with metadata (EXIF data)

我的NSData包含從外部硬件獲取的圖像,它具有元數據。.我已經通過將圖像上傳到AWS進行了測試。

我嘗試了以下兩種轉換:

UIImage *image = [UIImage imageWithData:_downloadedImageData ];

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

我進行了研究,發現無論何時將NSData轉換為UIImage或反之,元數據(EXIF數據)都會丟失。 我該如何進行轉換,以使我的元數據在兩次轉換(即UIImage NSDataUIImage中都退出,反之亦然

幫助非常感謝

試試這個代碼

創建路徑以保存圖像數據。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM