If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Load BMP into Memory, then get HBITMAP

I've spent two days trying to figure out how to load a 24 bit RGB bmp file into memory, and then later convert the DIB memory contents into a BITMAP and HBITMAP so I can selectObject the **** thing into a compatible memory DC. I thought GdipCreateBitmapFromGdiDib would get me there, but I still need to get the HBITMAP for the SelectObject and have no way to get an HBITMAP in this case because if I define a BITMAP structure, it is not a Windows record that has a handle to it. The doc says I cannot modify the BITMAP contents once the bitmap is created, so I can't just create a dummy bitmap of 1x1 pixel and then adjust the dimensions later.

It seems like the most simple and reasonable thing to be able to do, to allocate a chunk of ram, load a bmp file into it and then create a memory DC and bitmap structure (without re-copying the bitmap data into a newly allocated buffer) so that GDI functions can write on it. I can LoadBitmap things that are resources, and LoadImages from the file system, but there seems to be no way to treat a memory image of a BMP file as a DIB and get a handle to a bitmap without copying the **** thing...

Any insight on this would be greatly appreciated. I probably can find a solution in an open source project, and I guess I'll go searching there now.

Re: Load BMP into Memory, then get HBITMAP

Why would you want to load the bitmap in the memory first? Is that anything you want to modify? GDI+ allows you to load files from memory. Some people make use of this feature to load their encrypted images into the memory and decrypt the contents in memory and load the decrypted image from memory. I doubt the OP would want to change his GDI code to use GDI+. Too much work.