Introducing the WIC
Both the Hilo Browser and Annotator display photos, and Annotator allows you to alter photos. For Hilo the definition of a photo is any image type so the Hilo applications have to be able to load and display a wide range of file types. The Windows 7 Imaging Component provides this functionality. The WIC can load images that are made up of multiple frames and it can access metadata in the image file. The WIC supports all the common image formats and even allows developers to develop codecs (coder-decoder components) for new formats.
To use the WIC you must include the wincodec.h header file, it contains the definitions for the various interfaces used by the WIC, definitions of structures and GUIDs for the WIC objects, and the standard pixel formats. The WIC is not just one component, instead there are several components used to encode and decode the different formats supported. Different image formats store image data in different ways, so to load an image file you need a decoder component to decode the data into a format your application can use. When you save image information you need an encoder component to encode the data into the format defined by the image file format. If you know the type of image you wish to load then you can create a decoder with a call to CoCreateInstanceEx and provide the Class ID (CLSID) of the decoder object. If you do not know the image type you can use the WIC API to examine the file and choose the appropriate object. To do this you create an instance of the WIC factory object.
Listing 1 shows the Direct2DUtility::GetWICFactory method that is used by the Hilo applications to create an instance of the factory object. Like all the other WIC objects, the factory object is a COM object and so this code must be called in a COM apartment. You can initialize either an STA or an MTA apartment.