How to get BITMAPINFOHEADER

OK, I'm calling LoadImage with the LR_CREATEDIBSECTION to create a device independent bitmap.  What I need to do is to create a palette from the bitmaps color table so I can realize this palette on 256 color devices.  I found a function that will do this in the MSDN dibutil sample, but it requires a BITMAPINFOHEADER structure.  What I need to know, is hot to get the BITMAPINFOHEADER structure give the HBITMAP that I got from LoadImage.
dereklAsked:
Who is Participating?
 
chensuConnect With a Mentor Commented:
The following KB article demonstrates how to create a palette from the bitmap loaded with LoadImage.

HOWTO: How To Use LoadImage() to Read a BMP File
http://support.microsoft.com/support/kb/articles/q158/8/98.asp
0
 
edeyCommented:
there is this api:

The GetDIBColorTable function retrieves RGB (red, green, blue) color values from a range of entries in the color table of the DIB section bitmap that is currently selected into a specified device context.

UINT GetDIBColorTable(

    HDC hdc,      // handle of device context whose DIB is of interest
    UINT uStartIndex,      // color table index of first entry to retrieve
    UINT cEntries,      // number of color table entries to retrieve
    RGBQUAD *pColors      // pointer to buffer that receives color table entries
   );


GL
Mike
0
 
dereklAuthor Commented:
Alright, I can get a BITMAPINFOHEADER structure by calling GetObject to get a DIBSECTION object.  I guess what I need to know now is how to get to the RGBQUAD structures that hold the actual color data.  I know that these follow the BITMAPINFOHEADER structure in a BITMAPINFO structure, so how do I get a BITMAPINFO structure?  Can I just cast the BITMAPINFOHEADER I got from GetObject?
0
 
chensuCommented:
Have you taken a look at the KB article? There is the code you need.
0
 
GlennDeanCommented:
IF you're bitmap is gotten from a *.bmp file then you can get the BITMAPINFOHEADER by simply reading in the file.  
   First read in the BITMAPFILEHEADER struct and then the BITMAPINFOHEADER.  ALL *.bmp start off with these two structs, BUT, the rest of the file depends on data in those two structs.  Give it a shot - the above works perfect.  
   Once you verify the bitmap is really 8bpp, just read in 256 RGBQUAD data.
   Glenn
0
All Courses

From novice to tech pro — start learning today.