Click to See Complete Forum and Search --> : Load BMP into Memory, then get HBITMAP


sbailey
April 26th, 2009, 03:43 AM
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.

Kimbo
April 26th, 2009, 07:16 AM
I don't know if this is what your after: http://www.experts-exchange.com/Programming/Languages/CPP/Q_10319877.html
http://groups.google.com/group/microsoft.public.win32.programmer.gdi/msg/fab8e7e0fd5aa200

srelu
May 19th, 2009, 06:44 PM
Just one more detail, the first thing you need to know after you load a bitmap in the memory is the format of a BMP file. It's here: http://www.fortunecity.com/skyscraper/windows/364/bmpffrmt.html (or else, look for BMP on www.wotsit.org (http://www.wotsit.org)) .

Mike Harnad
May 21st, 2009, 07:41 AM
Have you tried looking at the articles in the Bitmap and Palettes section on Codeguru? There are articles that talk about working with 24 bit bitmaps.

CBasicNet
May 21st, 2009, 10:45 PM
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.