3
我目前使用AVCaptureStillImageOutput
來獲取全分辨率圖片。我還可以使用下面的代碼來獲取EXIF元數據:使用新的PHPhotoLibrary保存exif元數據
[self.stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler: ^(CMSampleBufferRef imageSampleBuffer, NSError *error)
{
CFDictionaryRef metaDict = CMCopyDictionaryOfAttachments(NULL, imageSampleBuffer, kCMAttachmentMode_ShouldPropagate);
CFMutableDictionaryRef mutableDict = CFDictionaryCreateMutableCopy(NULL, 0, metaDict);
NSLog(@"test attachments %@", mutableDict);
// set the dictionary back to the buffer
CMSetAttachments(imageSampleBuffer, mutableDict, kCMAttachmentMode_ShouldPropagate);
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer];
UIImage *image = [[UIImage alloc] initWithData:imageData];
[self.delegate frameReadyToSave:image withExifAttachments: mutableDict];
}];
元數據位於該mutableDict
變量。現在,我想將這張圖片保存在兩個不同的地方,包括元數據。我想將它保存在應用程序文件夾和照片庫中的磁盤上。現在
,我試圖挽救形象,另一種方法,使用下面的(你看到的圖像變量是一個自定義對象):
NSData* imageData = UIImageJPEGRepresentation(image.image, 1.0f);
[imageData writeToFile:image.filePath atomically:YES];
UIImageWriteToSavedPhotosAlbum(image.image, nil, nil, nil);
現在,圖像被正確保存,但不包含任何Exif元數據。
從我已閱讀的內容中,我需要使用PHPhotoLibrary來做到這一點,但文檔對此不太感興趣。這是我發現的:
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
PHAssetChangeRequest *createAssetRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:image.image];
} completionHandler:nil];
但是,如何保存元數據呢?
這節省的JPEG的EXIF一部分的元數據,但它並沒有在照片中顯示出來(在Mac上)。 –
[PHAssetChangeRequest creationRequestForAssetFromImageAtFileURL:tmpURL]應該在導入時讀出照片的EXIF元數據數據,並用必要的數據(記錄日期,位置數據)填充iCloud照片庫數據庫。照片是否以正確的時間戳顯示在iOS照片應用程序中? – holtmann
事實上,它適用於日期和地點。它不適用於標題,描述和關鍵字。至少不是我嘗試過的EXIF字段。 –