4
votes

I am able to add the Photo Sphere XMP Metadata to an equirectangular photo. I uploaded the photo with the XMP metadata to Google Photos, and the Google Photos is able to be recognized as a sphere photo. Then, I tried to save the photo with the XMP metadata to camera roll. I shared the photo to Google Photos from camera roll, but Google Photos does not know it's a sphere photo. I tried to download the photo and analyze it, and found the XMP metadata are all gone. It seems iOS will edit the metadata while the photo is saving to camera roll. Is there any way to preserve the photo's XMP metadata while saving it to camera roll?

// 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);
1
actually I found once we store the the image from NSData to UIImage, the UIImage will break the original data.srjohnhuang

1 Answers

0
votes

Key point: using

[PHAssetChangeRequest creationRequestForAssetFromImageAtFileURL: url] 

instead of

[PHAssetChangeRequest creationRequestForAssetFromImage:image]

since UIImage will break the original file, just use a temp url to save your original image raw data, and using creationRequestForAssetFromImageAtFileURL api.