【问题标题】:TYPE_E_TYPEMISMATCH changing Metadata Windows Universal AppTYPE_E_TYPEMISMATCH 更改元数据 Windows 通用应用程序
【发布时间】:2016-07-22 02:45:20
【问题描述】:

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

【问题讨论】:

  • 这里的问题完全相同。但我正在为 Widnows Phone 8.1 构建

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


【解决方案1】:

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

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

propertySet.Add("System.Photo.DateTaken", dateValue);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-28
    • 2015-09-01
    • 1970-01-01
    • 2013-07-14
    相关资源
    最近更新 更多