How to Create a Decoder Using an Image Filename
This topic describes how to create a bitmap decoder by using an image filename.
To create a bitmap decoder by using an image filename
Create an IWICImagingFactory object to create Windows Imaging Component (WIC) objects.
// Create WIC factory hr = CoCreateInstance( CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&m_pIWICFactory) );
Use the CreateDecoderFromFilename method to create an IWICBitmapDecoder from an image file.
HRESULT hr = S_OK; IWICBitmapDecoder *pIDecoder = NULL; IWICBitmapFrameDecode *pIDecoderFrame = NULL; hr = m_pIWICFactory->CreateDecoderFromFilename( L"turtle.jpg", // Image to be decoded NULL, // Do not prefer a particular vendor GENERIC_READ, // Desired read access to the file WICDecodeMetadataCacheOnDemand, // Cache metadata when needed &pIDecoder // Pointer to the decoder );
Get the first IWICBitmapFrameDecode of the image.
// Retrieve the first bitmap frame. if (SUCCEEDED(hr)) { hr = pIDecoder->GetFrame(0, &pIDecoderFrame); }
The JPEG file format only supports a single frame. Because the file in this example is a JPEG file, the first frame (
0
) is used. For image formats that have multiple frames, see How to Retrieve the Frames of an Image for accessing each frame of the image.Process the image frame. For additional information about IWICBitmapSource objects, see the Bitmap Sources Overview.
See Also