WIC Wrapper Library v1.1 has the following:
- new and completed methods for existing wrapper classes in the previous version;
- new classes: wic::Bitmap and wic::Palette;
- a new header containg enums, WicWrapEnums.h.
Download: WIC Wrapper Library [1.1].zip (255)
Example 2: Using wic::ImagingFactory::CreateBitmapFromHICON and wic::Bitmap
The following example is close to the previous one, except that it uses wic::ImagingFactory::CreateBitmapFromHICON to display an icon resource.
BOOL CDemoDoc::OnNewDocument() { BOOL bRet = FALSE; if(!CDocument::OnNewDocument()) return bRet; try { // get ImagingFactory instance const std::shared_ptr<wic::ImagingFactory> pImagingFactory = wic::ImagingFactory::GetInstance(); // create wic::Bitmap object from an icon resource HICON hIcon = (HICON)::LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_DEMO_ICON), IMAGE_ICON, 256, 256, LR_DEFAULTCOLOR); std::shared_ptr<wic::Bitmap> pBitmap = pImagingFactory->CreateBitmapFromHICON(hIcon); // get and initialize a format converter const std::shared_ptr<wic::FormatConverter> pFormatConverter = pImagingFactory->CreateFormatConverter(); pFormatConverter->Initialize(pBitmap); // calculate stride and necessary buffer size const CSize size = pBitmap->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); // create a Gdiplus::Bitmap object m_pBitmap = new Gdiplus::Bitmap(size.cx, size.cy, cbStride, PixelFormat32bppARGB, m_pBitmapBuffer); if(Gdiplus::Ok != m_pBitmap->GetLastStatus()) { throw(CAtlException(E_FAIL)); } bRet = TRUE; // success } catch(CAtlException& e) { CString strErrMsg; strErrMsg.Format(_T("Error 0x%08X"), e.m_hr); AfxMessageBox(strErrMsg, MB_ICONERROR); DeleteContents(); } return bRet; }
Demo Application
The demo application displays an icon resource when no image file is loaded.
Download: WIC Wrapper Library Sample [1.1].zip (276)