我想覆盖 System.Photo.DateTaken 值。这是我的方法:
private async void EditMetadata(uint rateNumber, DateTime newDate)
{
var memStream = new Windows.Storage.Streams.InMemoryRandomAccessStream();
var encoder = await Windows.Graphics.Imaging.BitmapEncoder.CreateForTranscodingAsync(memStream, _decoder);
var propertySet = new Windows.Graphics.Imaging.BitmapPropertySet();
var ratingValue = new Windows.Graphics.Imaging.BitmapTypedValue(rateNumber, Windows.Foundation.PropertyType.UInt32);
try
{
var dateValue = new Windows.Graphics.Imaging.BitmapTypedValue(newDate, Windows.Foundation.PropertyType.DateTime);
}
catch (System.Exception e)
{
Debug.WriteLine(e.Message);
}
propertySet.Add("System.Rating", ratingValue);
//propertySet.Add("System.Photo.DateTaken", dateValue);
try
{
await encoder.BitmapProperties.SetPropertiesAsync(propertySet);
}
catch (Exception err)
{
switch (err.HResult)
{
case unchecked((int)0x88982F41): // WINCODEC_ERR_PROPERTYNOTSUPPORTED
// The file format does not support this property.
break;
default:
throw err;
}
}
}
设置评分没有问题,但如果我这样称呼:
var dateValue = new Windows.Graphics.Imaging.BitmapTypedValue(newDate, Windows.Foundation.PropertyType.DateTime);
然后我收到此错误消息:
Type mismatch. (Exception from HRESULT: 0x80028CA0 (TYPE_E_TYPEMISMATCH))
我不知道为什么?DateCreated 具有 DataTime 类型。