使用 ALAssetsLibrary 时,我曾经使用以下代码将图像保存到带有适当 exif 的照片库:
NSInteger orientation = 2;// Or whatever
NSData *jpegData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
CMSetAttachment(imageDataSampleBuffer, kCGImagePropertyOrientation,
[NSNumber numberWithInt: orientation],
kCMAttachmentMode_ShouldPropagate);
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
CFDictionaryRef attachments = CMCopyDictionaryOfAttachments(kCFAllocatorDefault, imageDataSampleBuffer, kCMAttachmentMode_ShouldPropagate);
[library writeImageDataToSavedPhotosAlbum:jpegData metadata:(id)attachments completionBlock:^(NSURL *assetURL, NSError *error) {
...
...
}
目前尚不清楚在使用 PHPhotoLibrary 时如何翻译该代码。任何人都可以提供正确的方法来保存附件以及 jpeg 图像吗?