• Advertisement
Sign in to follow this  

GetDibits and GetObject

This topic is 4794 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
Advertisement
Have you allready put a bitmap into the structure, otherwise it could be a black and white bitmap.

Cheers
Chris

Share this post


Link to post
Share on other sites
I think the GetObject function will init the BITMAPINFO structure.

: )

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Does this do the trick SelectObject(hdcMem,hBitmap)?

: )

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement