Click to See Complete Forum and Search --> : Why "Invalid Parameter" for CreateDIBitmap ?


flipsflops
June 2nd, 1999, 03:24 PM
I am trying to display a 24bit True Colour image, using a block of uncompressed BGR data.


BITMAPINFO bitInfo;
BITMAPINFOHEADER biH;
HDC hdc, hdcdest;
HBITMAP hbm, oldhbm;
unsigned char *hPicPtr; // Holds bitmap data serially in 3 byte groups of Blue Green Red
.
.
hdc = CreateCompatibleDC( hdcdest );
hbm = CreateDIBitmap( hdc, &biH, CBM_INIT, hPicPtr, &bitInfo, DIB_RGB_COLORS );
check=GetLastError();
oldhbm = SelectObject(hdc, hbm);
.




The HBITMAP handle hbm is NULL after the CreateDIBitmap function has run, and GetLastError() returns 87 which is ROR_INVALID_PARAMETER. Have you any suggestions why the CreateDIBitmap function returns NULL ?

June 2nd, 1999, 04:57 PM
what does your initialization of the bitInfo and biH structures look like? I have noticed that sometimes these functions don't work correctly if they have a 'size' member in the structure that has not been initialized since they can not tell what kind of memory block you have passed it without this size parameter being initialized

HTH

flipsflops
June 3rd, 1999, 05:20 AM
Hi HTH,

Here is the structure initialisation:


biH.biSize = bitInfo.bmiHeader.biSize = sizeof(BITMAPINFO);
biH.biCompression = bitInfo.bmiHeader.biCompression = BI_RGB;
biH.biBitCount = bitInfo.bmiHeader.biBitCount = 24;
biH.biPlanes = bitInfo.bmiHeader.biPlanes = 1;
biH.biSizeImage = bitInfo.bmiHeader.biSizeImage = 0;
biH.biClrImportant = bitInfo.bmiHeader.biClrImportant = 0;
biH.biWidth = bitInfo.bmiHeader.biWidth = (long)(pcxheader.xmax - pcxheader.xmin);
biH.biHeight = bitInfo.bmiHeader.biHeight = -(long)(pcxheader.ymax - pcxheader.ymin);
biH.biXPelsPerMeter = bitInfo.bmiHeader.biXPelsPerMeter = 0L;
biH.biYPelsPerMeter = bitInfo.bmiHeader.biYPelsPerMeter = 0L;
biH.biClrUsed = bitInfo.bmiHeader.biClrUsed = 0L;
biH.biClrImportant = bitInfo.bmiHeader.biClrImportant = 0L;




The values I get in debug are:
biSize = 44
biCompression = 0
biBitCount = 24
biPlanes = 1
biSizeImage = 0 (also tried with bitmap size of 1601808)
biClrImportant = 0;
biWidth = 883
biHeight = -603 (negative for top down bitmap)
biXPelsPerMeter = 0
biYPelsPerMeter = 0
biClrUsed = 0
biClrImportant = 0

I used two structures in case I was not presenting the address of the second parameter
in the function CreateDIBitmap correctly.

Could it be because bmiColors != 0 in the BITMAPINFO structure ?