【问题标题】:iOS, how to keep Photo Sphere XMP Metadata while saving it to Camera Roll?iOS,如何在将 Photo Sphere XMP 元数据保存到相机胶卷时保留它?
【发布时间】:2016-07-10 10:09:32
【问题描述】:

我可以将Photo Sphere XMP Metadata 添加到 equirectangular 照片。 我将带有 XMP 元数据的照片上传到 Google Photos,Google Photos 能够被识别为球形照片。 然后,我尝试将带有 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就会破坏原始数据。

标签: ios exif alassetslibrary xmp camera-roll


【解决方案1】:

关键点:使用

[PHAssetChangeRequest creationRequestForAssetFromImageAtFileURL: url] 

而不是

[PHAssetChangeRequest creationRequestForAssetFromImage:image]

由于 UIImage 会破坏原始文件,只需使用临时 url 来保存原始图像原始数据,并使用 creationRequestForAssetFromImageAtFileURL api。

【讨论】:

    猜你喜欢
    • 2012-11-21
    • 1970-01-01
    • 2021-02-12
    • 2015-03-20
    • 1970-01-01
    • 2013-07-18
    • 2022-01-01
    • 1970-01-01
    相关资源
    最近更新 更多