Hi,
please help me to resolve the error of createDIBSection returns NULL.
Given below the code before calling the createDIBSection .
I tried to creates a DIB using CreateDIBSection but it returns NULL. GetLastError() returns 0. I could not find out what could be the error.
I think the size of deviceContext is high.I am new to this DIBSection function and not sure how internal function works
Code:
CDC * pSourceDC = AfxGetMainWnd()->GetDC();
BYTE * pDIBbuffer = new BYTE[sizeof(BITMAPINFOHEADER) + 256*sizeof(WORD)];
if (pDIBbuffer == NULL) { throw; }
BITMAPINFO * pDIB = (BITMAPINFO *)pDIBbuffer;
pDIB->bmiHeader.biSize= sizeof(BITMAPINFOHEADER);
pDIB->bmiHeader.biWidth= m_totalWidth;
pDIB->bmiHeader.biHeight= m_totalHeight;
pDIB->bmiHeader.biPlanes= 1;
pDIB->bmiHeader.biBitCount= 24; // MUST be 24-bit DIB for JPEG
pDIB->bmiHeader.biCompression= BI_RGB;
pDIB->bmiHeader.biSizeImage= 0;
pDIB->bmiHeader.biXPelsPerMeter= 0;
pDIB->bmiHeader.biYPelsPerMeter= 0;
pDIB->bmiHeader.biClrUsed= 0;
pDIB->bmiHeader.biClrImportant= 0;
WORD* color = (WORD*) pDIB->bmiColors;
for (i = 0; i < 256; i++)
{
*(color++) = i;
}
ColorPalette* colorPal = ColorPalette::getInstance();
CPalette* pOldPal = pSourceDC->SelectPalette( &(colorPal->GetWindowPalette()), FALSE);
pSourceDC->RealizePalette();
HBITMAP hBitmap = CreateDIBSection(pSourceDC->GetSafeHdc(),
pDIB,
DIB_PAL_COLORS,
(void **)&pvBits,// Here's where we put the image
NULL,
0);
Thank you