How to enumerate WIC codecs?

As shown in the previous article, Windows Imaging Component (WIC) comes with built-in codecs (for BMP, JPEG, GIF, PNG, TIFF, and HDPhoto image file formats). Additionally, WIC can deal with other image formats for which appropriate codecs are installed in the system.
Basically, to list available WIC codecs and eventually get info for each one, we can do the following:

  1. Call IWICImagingFactory::CreateComponentEnumerator in order to get a component enumerator either for WIC decoders or for WIC encoders.
  2. For each element of the enumerator, get IWICBitmapCodecInfo interface.
  3. Call IWICBitmapCodecInfo::GetFriendlyName, IWICBitmapCodecInfo::GetFileExtensions and other methods in order to get codec info.

Enumerate WIC codecs

Here is a sample function, implemented as described above. First argument is a pointer to a IWICImagingFactory instance, required for creating the component enumerator. Second argument can have either WICDecoder or WICEncoder value, to retrieve WIC decoders or encoders, respectively. Finally, last argument is an ATL list containing structures to be filled with codecs info.

 

Enumerate WIC decoders

CWICUtils::EnumDecoders simply calls CWICUtils::_EnumCodecs passing WICDecoder value.

 

Enumerate WIC encoders

CWICUtils::EnumEncoders calls CWICUtils::_EnumCodecs passing WICEncoder value.

 

Display WIC decoders info example

This example demonstrates how to use CWICUtils::EnumDecoders to display WIC decoders info in a simple console application.

Notes

      1. Include necessary ATL headers as well as WIC library headers.
      2. Add Windowscodecs.lib to linker additional dependencies or use pragma comment lib as follows:
      3. Here are the definitions of CCodecInfo and CWICUtils classes:

      4. The examples are intentionally made as simple as possible in order to just show how to do; you can modify and adapt them according to your particular needs.
      5. I’ve tested under Visual Studio 2008.
      6. The minimum operating system is Windows XP with SP3 or Windows XP with SP2 and redistributed WIC.

Resources

3 thoughts on “How to enumerate WIC codecs?

    1. Ovidiu Cucu Post author

      Thank you, Cristian!
      I think it is automatically released when CComPtr object goes out of scope.
      Am I missing something more?

      Reply

Leave a Reply