iOS,如何在保存到相机胶卷时保留Photo Sphere XMP元数据?

4
我能够为一个全景照片添加Photo Sphere XMP Metadata。 我已经上传了带有XMP元数据的照片到Google相册,它被成功识别为一张球形照片。 然后,我尝试将带有XMP元数据的照片保存到相机胶卷。 我从相机胶卷分享照片到Google相册,但是Google相册无法识别它是一张球形照片。 我尝试下载照片并分析它,发现所有的XMP元数据都消失了。 看来iOS系统在保存照片到相机胶卷时会编辑元数据。 那么在保存照片到相机胶卷时如何保留照片的XMP元数据呢?
// raw jpg data to NSData
NSString *img = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"equirectangular_orig.jpg"];
NSData* imgData = [[NSFileManager defaultManager] contentsAtPath:img];
NSMutableData *newImgData = [NSMutableData dataWithData:imgData];

// writing XMP metadata to newImgData
// ...
// ...

// saving the newImgData to new jpg file
NSString *path = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"equirectangular_xmp.jpg"];
NSURL *url = [NSURL fileURLWithPath:path];
[[NSFileManager defaultManager] removeItemAtPath:[url absoluteString] error:nil];
[newImgData writeToURL:url atomically:YES];

// saving the new jpg file to camera roll
UIImage *newImg = [UIImage imageWithData:newImgData];
UIImageWriteToSavedPhotosAlbum(newImg, self, nil, nil);

实际上,我发现一旦我们将NSData中的图像存储到UIImage中,UIImage就会破坏原始数据。 - srjohnhuang
1个回答

0
重点:使用 < / p>
[PHAssetChangeRequest creationRequestForAssetFromImageAtFileURL: url] 

而不是

[PHAssetChangeRequest creationRequestForAssetFromImage:image]

由于UIImage会破坏原始文件,所以只需使用临时URL保存原始图像原始数据,并使用creationRequestForAssetFromImageAtFileURL API。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接