1

I'm probably thinking about this all wrong, so please let me start by stating the goal: I want to compare two images by XORing them together, then save (not display) the result as a file. Actually, I want to then average all the bit values to get a percentage match, but that part isn't hard.

So BitBlt (remember BitBlt?) has a ROP called SRCINVERT that does exactly this. And screamingly fast. Works a treat. But... it wants a source and destination DC (Device Context) to work with... you can SelectObject a bitmap into those DC's, but you must have the DC's.

Making DC's is easy with CreateCompatibleDC(0); or even CreateDC(L"DISPLAY", NULL, NULL, NULL); but... those are based on the pixel depth, size, etc... of the current hardware display. {EDIT: Nop, CreateCompatibleDC(0); gets everything from the bitmap selected into it, I just wasn't actually using it.} And I don't care about that, I want to work with the pixel depth, etc... of the files I'm loading the bitmaps from. In fact, this is a command line program; it will never have a window. EDIT: But because the DC is for the actual screen, when using CreateDC(L"DISPLAY", NULL, NULL, NULL), I see the image on the display (overwriting the desktop) before it is saved out to a file.

Am I stuck? Do I have to find another graphics library to do my XOR function? Or is there a way to use BitBlt? More generally, is there a way to do GDI or GDIPlus type stuff with DC's that don't exist on the current system? Wouldn't that be a really useful thing to be able to do for programs that process image files without necessarily displaying the result?

James Newton
  • 698
  • 9
  • 19

2 Answers2

1

Once you select a bitmap into a memory context, its bit depth/pixel size will be taken over by the ones from the bitmap.

Seva Alekseyev
  • 59,826
  • 25
  • 160
  • 281
  • Thanks... sorry, I wasn't clear. The major issue is that doing a bitblt into a DC that is made for the display causes the image to be written to that display. I'll post my current code and perhaps that will make clear what I'm doing wrong. – James Newton Oct 20 '15 at 17:40
0

nevermind... silly boy... I was using CreateDC(L"DISPLAY", NULL, NULL, NULL); to make the destination DC and when I tried CreateCompatibleDC(0); I must have only changed the source DC... Oops. CreateCompatibleDC(0); works a treat.

https://github.com/JamesNewton/WinBitBltImageCompare

James Newton
  • 698
  • 9
  • 19