April 26th, 2009, 03:43 AM
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.
Tags for this Thread
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.