-
August 22nd, 2017, 12:18 AM
#1
CreateDIBSection returns NULL
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.
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);
Here hBitmap 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
I am capturing the application screenshot in different page.In one page,it returns NULL.Please help me on this.
Thank you
Last edited by 2kaud; August 22nd, 2017 at 02:40 AM.
Reason: Added code tags
-
August 22nd, 2017, 06:53 AM
#2
Re: CreateDIBSection returns NULL
What is the siye of a bitmap?
What do the GetDC(), SelectPalette() return?
Victor Nijegorodov
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|