So I have an image that I load using the CreateDecoderFromFilename method of the IWICImagingFactory I just created. It's easy enough to cast this to a Bitmap, but I want to extract the R-G-B-A channels independently so I can compare them to the values from a previous image, and calculate the error.
From the MSDN website...
IWICBitmapDecoder *pIDecoder = NULL;
IWICBitmapFrameDecode *pIDecoderFrame = NULL;
IWICFormatConverter *pIFormatConverter = NULL;
// Create the decoder.
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
);
// Retrieve the first bitmap frame.
if (SUCCEEDED(hr))
{
hr = pIDecoder->GetFrame(0, &pIDecoderFrame);
}
// Create the flip/rotator.
if (SUCCEEDED(hr))
{
hr = m_pIWICFactory->CreateFormatConverter(&pIFormatConverter);
}
// Initialize the format converter.
if (SUCCEEDED(hr))
{
hr = pIFormatConverter->Initialize(
pIDecoderFrame, // Input source to convert
GUID_WICPixelFormat32bppPBGRA, // Destination pixel format
WICBitmapDitherTypeNone, // Specified dither pattern
NULL, // Specify a particular palette
0.f, // Alpha threshold
WICBitmapPaletteTypeCustom // Palette translation type
);
}
//Create render target and D2D bitmap from IWICBitmapSource
if (SUCCEEDED(hr))
{
hr = CreateDeviceResources(hWnd);
}
if (SUCCEEDED(hr))
{
// Need to release the previous D2DBitmap if there is one
SafeRelease(&m_pD2DBitmap);
hr = m_pRT->CreateBitmapFromWicBitmap(pIFormatConverter, NULL, &m_pD2DBitmap);
}