1

我想覆盖 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 类型。

4

1 回答 1

0

遇到同样的问题,然后我找到了解决方案。请改用此代码:

var dateValue = new Windows.Graphics.Imaging.BitmapTypedValue(
                  Windows.Foundation.PropertyValue.CreateDateTime(
                    new DateTimeOffset(newDate)
                  ),
                  Windows.Foundation.PropertyType.DateTime
                );

propertySet.Add("System.Photo.DateTaken", dateValue);
于 2016-07-21T18:27:55.680 回答