While saving photo file Properties, it throws Argument Exception on SavePropertiesAsync() call for only certain values.
The code below tries to copy all properties supported, but it throws exception only certain ones.
e.g. System.Photo.FocalLength: 5.9 => On save, it throws the exception. I confirmed it's double value type and all look good, but it throws error.
Total 17 values cause the same issue.
Error: key=System.Photo.FocalLength, value type = Double, exception= The parameter is incorrect.
Error: key=System.Image.ResolutionUnit, value type = Int16, exception= The parameter is incorrect.
Error: key=System.GPS.Latitude, value type = Double[], exception= The parameter is incorrect.
All 17 errors are out of numeric types.
public static async Task CopyProperties(StorageFile sourceFile, StorageFile copyToFile)
{
ImageProperties imgPs = await sourceFile.Properties.GetImagePropertiesAsync();
ImageProperties imgPt = await copyToFile.Properties.GetImagePropertiesAsync();
var propList = GetPhotoPropertyList(); //get all key list of Photo Metadata Policies
IDictionary<string, object> photoPropertyDic = await sourceFile.Properties.RetrievePropertiesAsync(propList);
foreach (var key in photoPropertyDic.Keys)
{
App.l($"{key}: {photoPropertyDic[key]}", 3);
var value = photoPropertyDic[key];
if (value == null) continue;
var keyvalue = new KeyValuePair<string, object>(key, value);
var propListToSave = new List<KeyValuePair<string, object>>();
propListToSave.Add(keyvalue);
try
{
await imgPt.SavePropertiesAsync(propListToSave); //Test code to save individually to see which one causes an error.
}
catch(Exception ex)
{
App.l($"Error: key={key}, value type = {value.GetType().Name}, exception= {ex.Message}", 3); //Log error
}
}
GetPhotoPropertyList method - include only partial for easy testing.
private static List<string> GetPhotoPropertyList()
{
var lst = new List<string>();
lst.Add("System.ApplicationName"); //The photo metadata policy for the System.ApplicationName property.
lst.Add("System.Author"); //The photo metadata policy for the System.Author property.
lst.Add("System.Photo.FocalLength"); //The photo metadata policy for the System.Photo.FocalLength property.
lst.Add("System.GPS.Latitude"); //The photo metadata policy for the System.GPS.Latitude property.
//lst.Add("System.GPS.Latitude"); //The property proxy for the System.GPS.Latitude photo metadata policy.
lst.Add("System.GPS.LatitudeRef"); //The photo metadata policy for the System.GPS.LatitudeRef property.
return lst;
}