WIC Wrapper Library – Version 1.0

I’ve begun writing a series of wrapper classes over WIC (Windows Imaging Component) interfaces, that can easily be used in MFC, ATL, or Win32 applications without worry about directly dealing with COM interfaces.
This first version contains basic operation for loading, scaling and converting source image formats that are supported by WIC.
Download: WIC Wrapper Library.zip (1196 downloads)
WIC Wrapper Library.zip archive contains the following:

    • Header files, located in \WicWrap\Include folder;
    • WicWrapDLL.dll, both Debug and Release builds, located in \WicWrap\Bin folder;
    • WicWrapDLL.lib, both Debug and Release builds, located in \WicWrap\Lib folder.

Adding WIC Wrapper Library to a project

As said before, WIC Wrapper Library can be used in MFC, ATL or Win32 projects. Here is an example shownig the steps for adding this library to an existing project:

        1. copy WicWrap folder, in the solution directory;
        2. in Solution Explorer window right-click on project name and choose the Properties menu item;
        3. choose All Configurations, go to Configuration Properties\C/C++ and add $(SolutionDir)WicWrap\Include in the Additional Include Directories field;
        4. go to Configuration Properties\Linker\Input and add WicWrapDLL.lib (also for all configurations);
        5. choose Debug configuration, go to Configuration Properties\Linker and add $(SolutionDir)WicWrap\Lib\Debug in the Additional Library Directories field;
        6. choose Release configuration, go to Configuration Properties\Linker and add $(SolutionDir)WicWrap\Lib\Release in the Additional Library Directories field
        7. copy the debug and release versions of WicWrapDLL.dll in solution Debug and Release output directories;
        8. in Solution Explorer window, right-click on project name, choose Add\Existing Item and add the WicWrap header files from \WicWrap\Include folder;
        9. include WicWrap.h in the project source code, e.g in stdafx.h .

Using WIC Wrapper Library

Next is a simple example, in an MFC program:

BOOL CDemoDoc::OnOpenDocument(LPCTSTR lpszPathName)
    BOOL bRet = FALSE;
        return bRet;

        // get ImagingFactory instance
        const std::shared_ptr<wic::ImagingFactory> pImagingFactory 
            = wic::ImagingFactory::GetInstance();

        // create BitmapDecoder from a file
        const std::shared_ptr<wic::BitmapDecoder> pBitmapDecoder = 

        // get first frame
        const std::shared_ptr<wic::BitmapFrameDecoder> pBitmapFrameDecoder 
            = pBitmapDecoder->GetFrame(0);

        // get and initialize a format converter  
        const std::shared_ptr<wic::FormatConverter> pFormatConverter 
            = pImagingFactory->CreateFormatConverter();

        // calculate stride and necessary buffer size
        const CSize size = pBitmapFrameDecoder->GetSize();
        const UINT cbStride = 4 * size.cx;
        const UINT cbBufferSize = cbStride * size.cy;

        // allocate buffer then copy pixels
        m_pBitmapBuffer = new BYTE[cbBufferSize];
        pFormatConverter->CopyPixels(CRect(0, 0, size.cx, size.cy), 
            cbStride, cbBufferSize, m_pBitmapBuffer);

        // creat a Gdiplus::Bitmap object
        m_pBitmap = new Gdiplus::Bitmap(size.cx, size.cy, cbStride, 
            PixelFormat32bppARGB, m_pBitmapBuffer);
        if(Gdiplus::Ok != m_pBitmap->GetLastStatus())
        bRet = TRUE; // success
    catch(CAtlException& e)
        CString strErrMsg;
        strErrMsg.Format(_T("Error 0x%08X"), e.m_hr);
        AfxMessageBox(strErrMsg, MB_ICONERROR);
    return bRet;

More details can be found in the demo application, attached below.

Demo Application

The demo application is a simple image viewer made in a simple SDI MFC project.
Download: WIC Wrapper Library Sample [1].zip (1514 downloads)

WIC Wrapper Library - Sample Application
WIC Wrapper Library – Sample Application

Note: the image shown in the sample application is taken from SoftIcons.com site.

WIC-related articles and resources

1 thought on “WIC Wrapper Library – Version 1.0”

  1. I’ve been searching for a native (64-bit) C interface to simply load, scale/draw and unload image files. I found this, but I don’t think it supports 64-bit and, though you say it is usable from “Win32” only MFC examples are provided. Has this ever evolved or was it abandoned?


Leave a Comment