2017-04-25 50 views
0

我试图将某些属性保存到Windows 10 UWP应用程序中的图像文件中,在手机上。ImageProperties.SaveImagePropertiesAsync()不保存更改

var fileProperties = await file.Properties.GetImagePropertiesAsync(); 

fileProperties.Rating = 25; 
fileProperties.Title = "Title"; 
fileProperties.DateTaken = DateTime.Now; 

await file.Properties.SavePropertiesAsync(); 

由于某些原因,属性未保存。

该文件被预先创建这样的:

var file = await _sourceFolder.CreateFileAsync(pathToFile, CreationCollisionOption.ReplaceExisting); 
await bitmap.SaveToStorageFile(file); 

其中位图是WriteableBitmap的类型的。 图像保存到文件,但属性不是。

有没有人知道我做得不对?没有例外,也没有关于它为什么不成功的信息。

回答

1

这里的问题是StorageFile.Properties.SavePropertiesAsync,它获得StorageItemContentProperties。它使用原始数据保存到文件中。您可以使用ImageProperties.SavePropertiesAsync方法。它使用新的ImageProperties数据保存到文件。

例如:

var fileProperties = await file.Properties.GetImagePropertiesAsync(); 
fileProperties.Rating = 25; 
fileProperties.Title = "title"; 
fileProperties.DateTaken = DateTime.Now; 
await fileProperties.SavePropertiesAsync(); 
+0

哦,我的坏,然后...感谢您的帮助。标记你的答案是唯一的答案。有用。 – robcsi