I want to overwrite the System.Photo.DateTaken value. This is my method:
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;
}
}
}
There is no problem by setting the rating, but if I call this:
var dateValue = new Windows.Graphics.Imaging.BitmapTypedValue(newDate, Windows.Foundation.PropertyType.DateTime);
then I get this error message:
Type mismatch. (Exception from HRESULT: 0x80028CA0 (TYPE_E_TYPEMISMATCH))
I don't know why? The DateCreated has the DataTime type.
Was having the same issue and then I found a solution. Use this code instead:
var dateValue = new Windows.Graphics.Imaging.BitmapTypedValue(
Windows.Foundation.PropertyValue.CreateDateTime(
new DateTimeOffset(newDate)
),
Windows.Foundation.PropertyType.DateTime
);
propertySet.Add("System.Photo.DateTaken", dateValue);
User contributions licensed under CC BY-SA 3.0