Iím trying to encapsulate a Device Independent Bitmap (DIP) and Iím running into problems. Iím using intensively DIBSections and now I need to load a BMP from a file without passing through a DC to fill the DIBSection. (I donít want to remap the color to those of the DC) Since there is no direct API I searched and found that the LoadImage has a parameter (LR_CREATEDIBSECTION) that specifies that the API should create a DIBsection. So far, so good. The problem comes when I try to access the pixels of DIBSection that uses a color table. I can not find a way to get this table from the system created DIBSection! The only (ugly) workaround I can see is to load the table from the file.
Has some API guru a good idea?


Posted on 2006-07-26 12:16:16 by Biterider

After getting a handle to the DibSection using LoadImage (LR_CREATEDIBSECTION), couldn't you access it using GetObject. This should map it to a DIBSECTION structure where you can get a pointer to the bit values. I haven't tested this specifically using LoadImage but I thought that might be the next step.

// Retrieve DIBSECTION data from the new DIB
GetObject(hDIB, sizeof DIBSECTION, &DibSection);

Posted on 2006-07-26 17:11:26 by Kayaker
Hi Kayaker
Unfortunatey GetObject fills a structure (DIBSECTION)that doesn't contain BITMAPINFO. This is the only structure that you can use to access the color table.  :sad:
Reading some literature, it seems that the only way is to use the GetDIBColorTable api after the colors are mapped to a DC and that is what I don't want to do.

Posted on 2006-07-27 00:53:32 by Biterider
Except for the "dirty" method of retrieving the palette from file (which is really much easier and failproof), you can use the structure BITMAPCOREINFO. Which I think is really obsolete. Search MSDN's examples for BITMAPCOREINFO: there are DIBUTIL.c, DIBMP.c, SAVEBMP.c, DIBS.c. With win2k and winxp's internal OOP approach around HANDLE/HBITMAP/.. , I doubt the shown tricks would work.
Posted on 2006-07-27 07:45:19 by Ultrano