CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2009

    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.

  2. #2
    Join Date
    Nov 2005

    Re: Load BMP into Memory, then get HBITMAP

  3. #3
    Join Date
    Nov 2007

    Re: Load BMP into Memory, then get HBITMAP

    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/skyscrape.../bmpffrmt.html (or else, look for BMP on www.wotsit.org) .

  4. #4
    Join Date
    Apr 1999

    Re: Load BMP into Memory, then get HBITMAP

    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.
    Gort...Klaatu, Barada Nikto!

  5. #5
    Join Date
    Sep 2002

    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.