Tag Archives: codecs

MFC-extension WIC File Dialogs

A previous article showed how to enumerate WIC (Windows Imaging Component) codecs, that are available in system.
Now, let’s use the codecs list in order to make File Open and File Save As dialogs which are dealing with WIC-compliant image files, i.e. having “File of type” filter list according to available WIC codecs (see the images, below).

WIC Open File Dialog

WIC Open File Dialog

 

WIC Save As File Dialog

WIC Save As File Dialog

CWICFileDialog class

CWICFileDialog is derived from CFileDialog MFC class. It basically overrides CFileDialog::DoModal and constructs the file types filter.

For implementation details, download the demo project attached here.

Demo project

The demo project is just a simple dialog-based MFC application that uses CWICFileDialog. It does nothing else but only shows the file dialogs.
Of course, in practice, you can use CWICFileDialog class in more complex applications like image file viewers, image file converters, and so on.

Resources

See also

Downloads

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