LoadBitmap Function

This is a discussion on LoadBitmap Function within the Windows Programming forums, part of the Platform Specific Boards category; Hi, I am trying to write some code to load a bitmap, so that I can retrieve its pixel data. ...

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    36

    LoadBitmap Function

    Hi,

    I am trying to write some code to load a bitmap, so that I can retrieve its pixel data. On the MSDN website, I found a function called LoadBitmap, which seems to do what I want :
    http://msdn.microsoft.com/library/de...tmaps_4c34.asp

    The function prototype is:

    HBITMAP LoadBitmap(
    HINSTANCE hInstance, // handle to application instance
    LPCTSTR lpBitmapName // name of bitmap resource
    );


    However, I am quite new to programming, and I don't know how to use the function. It says that hInstance is the "handle to the instance of the module whose executable file contains the bitmap to be loaded."

    What on earth does this mean? What is a handle? What is the executable file that it is talking about?

    As you can probably tell, my knowledge of C++ has a fair way to go!

    Thank you.

  2. #2
    Registered User
    Join Date
    Aug 2003
    Posts
    288
    I believe you can just use GetModuleHandle(NULL) to get the hInstance.

    edit:

    thats assuming you have the bitmap resource in the same executable. if you want to load a bitmap from file, you should use LoadImage() with the *_LOADFROMFILE flag.

  3. #3
    Registered User
    Join Date
    Aug 2006
    Posts
    74
    Quote Originally Posted by ejohns85
    I am trying to write some code to load a bitmap, so that I can retrieve its pixel data.
    Are you just trying to display the bitmap to the screen? Or are you actually trying to look at individual pixel information?

    Quote Originally Posted by ejohns85
    What on earth does this mean? What is a handle? What is the executable file that it is talking about?
    There are two ways to load a bitmap:
    1. From a program resource.
    - The bitmap is defined in a resource file (.rc) and is basically stored inside your .exe when compiled. Therefore when distributing your program you only have to give someone the .exe rather than the .exe + .bmp. Of course the .exe would be bigger in this case.
    2. From a file on the hard drive (.bmp)

    Ex of #1:
    Code:
    // This is file Resource.rc
    deck_cards BITMAP Cards.bmp // Define a bitmap "Cards.bmp" with the ID of deck_cards.

    Code:
    // This is a .cpp file where all your other code is.
    HBITMAP cardsBmp = LoadBitmap(instance, "deck_cards"); // Load bitmap from program resources rather than from hard drive.




    Ex: #2 probably something like:
    Code:
    HBITMAP bmpCards = (HBITMAP)LoadImage(instance, "Cards.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
    Last edited by Kurisu33; 08-27-2006 at 10:15 AM.

  4. #4
    ... arjunajay's Avatar
    Join Date
    May 2005
    Posts
    203
    But I think the documentation says LR_LOADFROMFILE is not supported in Win NT.
    If you want to access induvidual pixels and display the bitmap after manipulating them I think you should create a dibsection using CreateDIBSection().
    But if you are reading from a file and you don't want to display it, you need NOT do that; instead simply learn about the bitamp file format and read in relevant info from file.

    P.S. If you don't have a clue about handles and the like, you should read a tutorial for beginers or a good book before messing with bitmaps.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Replies: 16
    Last Post: 09-23-2008, 03:32 AM
  3. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  4. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  5. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 06:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21