TYPE_E_TYPEMISMATCH更改元数据Windows Universal App

时间:2014-06-04 09:08:36

标签: metadata windows-8.1 windows-phone-8.1 type-mismatch win-universal-app

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

1 个答案:

答案 0 :(得分: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);