代码之家  ›  专栏  ›  技术社区  ›  F. Renato

为什么在尝试向GIF图像中添加元数据时会出现异常?

  •  1
  • F. Renato  · 技术社区  · 7 年前

    我正在尝试在通用Windows平台中向GIF图像添加附加信息。我想我可以使用GIF格式(GIF标准)的注释扩展块来完成。

    因此,我按照以下链接中的说明进行操作: https://docs.microsoft.com/en-us/previous-versions/windows/apps/jj709942(v=win.10) , https://stackoverflow.com/a/33093592 以及我需要的元数据查询: https://docs.microsoft.com/it-it/windows/win32/wic/-wic-native-image-format-metadata-queries .

    我的理解是:

    1. BitmapEncoder 从 BitmapDecoder
    2. 制造新的 BitmapPropertySet KeyValuePair<string, BitmapTypedValue>
    3. 使用字符串 "/commentext/TextEntry" 作为元数据查询
    4. 呼叫 SetPropertiesAsync

    我想出了以下代码:

    var decoder = await BitmapDecoder.CreateAsync(stream);
    var encoder = await BitmapEncoder.CreateForInPlacePropertyEncodingAsync(decoder);
    
    var metadataValue = new BitmapTypedValue("my additional information", PropertyType.String);
    
    var properties = new List<KeyValuePair<string, BitmapTypedValue>>();
    
    properties.Add(new KeyValuePair<string, BitmapTypedValue>("/commentext/TextEntry", metadataValue));
    
    await encoder.BitmapProperties.SetPropertiesAsync(properties);
    
    await encoder.FlushAsync();           
    await stream.FlushAsync();
    

    有人能帮我吗?我做错了什么?

    0 回复  |  直到 7 年前