[WIC] How to get a metadata query path from a heirarchy of IWICMetadataReader objects RRS feed

  • Question

  • I'm enumerating all metadata in an image recursively using IWICMetadataBlockReader and IWICMetadataReader. But then I'd like to change a piece of metadata read by one of the nested IWICMetadataReader objects. This seems quite difficult. The easiest way would be if I could use the schema and Id of the IWICMetadataReader objects to get a query path for an IWICMetadataQueryWriter. Does anyone have any ideas?

    Tuesday, September 17, 2019 7:20 AM

All replies

  • Hi Ben48,

    The Windows Imaging Component do support to select the metadata item via the metadata query language. The following example demonstrates how to set metadata to the destination image. This is done by calling the query writer's SetMetadataByName method using a query expression and the data stored in a PROPVARIANT.

                    hr = piFrameEncode->GetMetadataQueryWriter(&piFrameQWriter);
    if (SUCCEEDED(hr))
                    // Add additional metadata.
                    PROPVARIANT    value;
                    value.vt = VT_LPWSTR;
                    value.pwszVal= L"Metadata Test Image.";
                    hr = piFrameQWriter->SetMetadataByName(L"/xmp/dc:title", &value);

    For the detail about metadata query language please refer to the docs below:

    Metadata Query Language Overview

    And below is a full code sample about How-to: Re-encode a JPEG Image with Metadata:

    Please feel free to let me know if there is any misunderstanding or detailed requirements.

    Regards & Fei

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Friday, September 20, 2019 9:29 AM
  • Thanks for the reply. I was actually trying to make a generic reader/writer that would enumerator the metadata and then allow you to edit it. I have found that actually there are two ways to do this. One is to use IWICMetadataQueryReader::GetEnumerator to enumerator the metadata query paths, but this misses some information compared to enumerating the metdata bocks. 

    I found it is actually possible for the most part to create a query path from a hierarchy of IWICMetadataBlockReader and IWICMetadataReader objects. I found this function - WICMapGuidToShortName - which can take the result of IWICMetadataReader::GetMetadataFormat and return a string to be used in the query path. This can be used together with ids and schemas and the syntax described on this page - to get the query path.

    Friday, October 25, 2019 6:35 PM