GetDibits and GetObject

Started by
3 comments, last by JoeZ 19 years, 3 months ago
Hi, I have a question regarding GetObject(hbitmap,sizeof(BITMAPINFO),&bminfo); The function failed to init the biBitCount field. Does the function work with getting bitmapinfo structure? Maybe I should use GetObject(bitmap,sizeof(DIBSECTION),&ds);? I know that the bitmap bit count(32bit) and I init that field myself then I try to use GetDibits to get the pixel values from the bitmap and again it failed. Here is my code. Do you see anything wrong? //bitmap already loaded GetObject(hBitmap,sizeof(BITMAP, &bitmap); GetObject(hBitmap,sizeof(BITMAPINFO),&bminfo); HDC hdcMem = CreateCompatibleDC(NULL); SelectObject (hdcMem,hBitmap); COLORREF *pix = new [bitmap.bmWidth * bitmap.bmHeight] GetDibits( hdcMem, hbitmap, 0, bitmap.bmHeight, pix, &bminfo, DIB_RGB_COLORS); int r = GetRValue(pix[0]); int g = GetG.. int b .. r, g, b are all equal to 205 but the color at (0,0) is pure blue. Thanks!
Advertisement
Have you allready put a bitmap into the structure, otherwise it could be a black and white bitmap.

Cheers
Chris
CheersChris
I think the GetObject function will init the BITMAPINFO structure.

: )
well if you just create a dc then it will have a black and white bitmap in it. :), Unless you create a dc from another dc it will be initialized that way.

Are you checking that GetObject's return code?? it returns 0 on failure.

Cheers
Chris
CheersChris
Does this do the trick SelectObject(hdcMem,hBitmap)?

: )

This topic is closed to new replies.

Advertisement