d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Win32 Api And Windows Gdi > I Doubt This Exists
1237Next
Add Reply New Topic New Poll
Member
Posts: 31,680
Joined: Nov 10 2007
Gold: 1.00
Nov 9 2009 04:39pm
Is there any way to compare bitmap images to each other, without manually doing it yourself? Specifically using the Win32 API (not MFC) and/or Window's GDI.

Too lazy to google right now, thanks.
Member
Posts: 11,637
Joined: Feb 2 2004
Gold: 434.84
Nov 9 2009 04:50pm
Quote (Muted @ Nov 9 2009 06:39pm)
Is there any way to compare bitmap images to each other, without manually doing it yourself? Specifically using the Win32 API (not MFC) and/or Window's GDI.

Too lazy to google right now, thanks.


I'm probably thinking of this incorrectly but if you want to compare the two image files just programatically take the the md5 of each and compare them. For an in memory comparison I'm not sure, I'd also have to google it.
Member
Posts: 31,680
Joined: Nov 10 2007
Gold: 1.00
Nov 9 2009 05:55pm
Quote (rockonkenshin @ 9 Nov 2009 17:50)
For an in memory comparison I'm not sure, I'd also have to google it.


Well honestly, if you had the one image you'd like to compare written out in an array, you could use GetPixel or GetGDI.. forget what it was (GetDCLine() or something similar) and compare one by one until you find a mis-match.
You can capture images via Window's GDI through this method: http://msdn.microsoft.com/en-us/library/dd183402(VS.85).aspx but, there's nothing about comparing images.

Or this:

Code

void ScreenShot() {

   HDC hdcScreen, hdcMemory;
   int cxScreen, cyScreen;
   HBITMAP hbmMemory, hbmOld;
   BITMAPINFO bi;
   void* data;

   // get the HDC of the screen
   hdcScreen = GetDC(NULL);

   // get the screen size
   cxScreen = GetSystemMetrics(SM_CXSCREEN) / 10;
   cyScreen = GetSystemMetrics(SM_CYSCREEN) / 10;

   // create a compatible memory dc/bitmap pair
   hdcMemory = CreateCompatibleDC(hdcScreen);
   hbmMemory = CreateCompatibleBitmap(hdcScreen, cxScreen, cyScreen);
   hbmOld = (HBITMAP)SelectObject(hdcMemory, hbmMemory);

   // "capture" the screen into this pair
   BitBlt(hdcMemory, 0, 0, cxScreen, cyScreen, hdcScreen, 0, 0, SRCCOPY);

   // now that we got the screen into the HBITMAP, get its bits

   // we want to get it as 24-bpp
   ZeroMemory(&bi, sizeof(BITMAPINFO));
   bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
   bi.bmiHeader.biWidth = cxScreen;
   bi.bmiHeader.biHeight = cyScreen;
   bi.bmiHeader.biBitCount = 24;
   bi.bmiHeader.biPlanes = 1;

   // first call with a NULL pointer to fill in rest of bi.bmiHeader
   GetDIBits(hdcMemory, hbmMemory, 0, cyScreen, NULL, &bi, DIB_RGB_COLORS);

   // allocate memory (size is in bi.bmiHeader.biSizeImage)
   data = malloc(bi.bmiHeader.biSizeImage);

   // now get the data
   GetDIBits(hdcMemory, hbmMemory, 0, cyScreen, data, &bi, DIB_RGB_COLORS);

   // clean-up
   SelectObject(hdcMemory, hbmOld);
   DeleteDC(hdcMemory);
   DeleteObject(hbmMemory);

   return;
}


But even then, I'm unsure of how to access the image like that.
If I knew how to loop through the bits in the image, and one that's stored on the harddrive, that'd be great.

This post was edited by Muted on Nov 9 2009 06:02pm
Member
Posts: 6,953
Joined: Sep 27 2003
Gold: 518.50
Nov 9 2009 06:02pm
Seeing as how a "bitmap" is just a name for a collection of color values with some header information. How do you compare two arrays?
Member
Posts: 31,680
Joined: Nov 10 2007
Gold: 1.00
Nov 9 2009 06:03pm
Quote (ASBands @ 9 Nov 2009 19:02)
Seeing as how a "bitmap" is just a name for a collection of color values with some header information.  How do you compare two arrays?


Loops obviously, but I shouldn't have to write a file of it (a picture in memory) just to compare it to another image.
Member
Posts: 9,475
Joined: Mar 14 2005
Gold: 110.00
Nov 9 2009 06:31pm
There are roughly a billion ways to "compare" things. You need to elaborate. Do you just want to know if the contents of two images files match or do you want to know where they differ? Are close matches OK? etc...
Member
Posts: 31,680
Joined: Nov 10 2007
Gold: 1.00
Nov 9 2009 06:37pm
Quote (llamaoo7 @ 9 Nov 2009 19:31)
There are roughly a billion ways to "compare" things.  You need to elaborate.  Do you just want to know if the contents of two images files match or do you want to know where they differ? Are close matches OK? etc...


http://dictionary.reference.com/browse/compare
Quote
–verb (used with object) 1. to examine (two or more objects, ideas, people, etc.) in order to note similarities and differences: to compare two pieces of cloth; to compare the governments of two nations.


To compare two images, one against another.
To see if they differ in any way, shape or form.
EG: The first five bits (00, 01, 01, 01, 02) against the base image (00, 01, 01, 01, 03).
Member
Posts: 9,475
Joined: Mar 14 2005
Gold: 110.00
Nov 9 2009 06:50pm
Quote (Muted @ 9 Nov 2009 19:37)
http://dictionary.reference.com/browse/compare


To compare two images, one against another.
To see if they differ in any way, shape or form.
EG: The first five bits (00, 01, 01, 01, 02) against the base image (00, 01, 01, 01, 03).


So what kind of output do you want? If you just want a true/false value, just use the MD5, unless there is something weird with the metadata that you don't want to compare.
Member
Posts: 31,680
Joined: Nov 10 2007
Gold: 1.00
Nov 9 2009 06:56pm
Quote (llamaoo7 @ 9 Nov 2009 19:50)
So what kind of output do you want?  If you just want a true/false value, just use the MD5, unless there is something weird with the metadata that you don't want to compare.


That means little to nothing to me: http://en.wikipedia.org/wiki/MD5
Member
Posts: 9,475
Joined: Mar 14 2005
Gold: 110.00
Nov 9 2009 07:02pm
Quote (Muted @ 9 Nov 2009 19:56)
That means little to nothing to me: http://en.wikipedia.org/wiki/MD5


Consult your dictionary. I'm done here.
Go Back To Programming & Development Topic List
1237Next
Add Reply New Topic New Poll