Checking to see if two 'HBITMAP's are the same?? (PLEASE help)

This is a discussion on Checking to see if two 'HBITMAP's are the same?? (PLEASE help) within the Windows Programming forums, part of the Platform Specific Boards category; Hi. Thanks for reading this. In my application I would like to see if a bitmap on a static control ...

  1. #1
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Unhappy Checking to see if two 'HBITMAP's are the same?? (PLEASE help)

    Hi. Thanks for reading this. In my application I would like to see if a bitmap on a static control is the same as a bitmap I load in a loop. It looks like this:

    Code:
    	HBITMAP hBitmap;    // Handle to current tile's bitmap object
    	FILE *pFile = fopen("myMap.txt", "wb");
    
    	// TODO: Loop through the tile vector objects and write
    	//       them to the specified file
    	for (int current = 0; current < m_wndTile.size(); current++) 
    	{
    		hBitmap = m_wndTile[current]->GetBitmap();    // Get current tile's bitmap data
    		for (int rsrc = 131; rsrc <= 132; rsrc++)   // Loop resource bitmaps
    		{
    			/* This section will check for a matching */
    			/* resource id. if one is found, it will  */
    			/* write the tile data to the file        */
    
    		}
    	}
    	fclose(pFile);      // Close the file
    Inside the 'for' loop containing the 'rsrc' of type 'int' is where I need to compare the two. I am making a level editor in MFC for a game I was working on a while back. How would I check to see if the 'hBitmap' object is equal to the bitmap loaded with the resource ID 'rsrc'? Please help if possible.

    Thanks,
    Matt U.

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    You would first check sizes, colour depth ect.

    GetObject() with a BITMAP struct

    Then check the actual bits.

    Realy all you need to do is convert both to byte arrays (inc header) and compare one to the other in a loop.

    GetDIBits() may help.

    But the images may be the same 'picture' but diff sizes, colour depths ect and you will not be able to tell.

    Could perform a threshold (all values above/below the threshold are turned black or white) or stretch ( all values are multiplied by a constant ie 4 to accentuate the image) or a histogram (the differnce from on pixcell to another is recorded looking peaks which are edges) but it depends on what you are looking for.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,659
    This *might* work as long as the original bitmap was loaded with LoadImage() *and* it wasn't loaded from a file *and* the LR_SHARED flag is always used.

    Code:
    if(hBitmap == (HBITMAP)
       LoadImage(hInstance, MAKEINTRESOURCE(rsrc), IMAGE_BITMAP, 0, 0, LR_SHARED))
     // do something
    Just a thought anyway. Note that it doesn't really compare the bitmaps, it just sees if they have the same handle, which may well be improbable, depending on your circumstances.



    ITSA
    Socket Library!

  4. #4
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Realy all you need to do is convert both to byte arrays
    GetPixel(hDC, x, y)
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 09:38 AM
  2. Overflow and range checking for mul/div
    By Elysia in forum C++ Programming
    Replies: 28
    Last Post: 06-06-2008, 02:09 PM
  3. Interpreter.c
    By moussa in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 05:59 PM
  4. Forced moves trouble!!
    By Zishaan in forum Game Programming
    Replies: 0
    Last Post: 03-27-2007, 06:57 PM
  5. Problems about gcc installation
    By kevin_cat in forum Linux Programming
    Replies: 4
    Last Post: 08-09-2005, 09:05 AM

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