There are three screenshots. There is a short text on them with a code like X123XX123.

  1. white text on a dark background (no distortion)
  2. red text on a dark background (without distortion, the text is the same as 1.)
  3. white text on the same background as always, but the code is different. (no distortion)

What comparison method should you choose to quickly compare options 1-2 and 2-3?

  • 1-2 You need to make sure that the text is the same but it turned red.
  • 2-3 Make sure the text is different.

Screenshots about 150x80px in size.

  • With 150 * 80 you can do almost anything. What is the problem with speed? - Qwertiy
  • Perhaps there are no problems with speed, this is like an addition to the question in which I don’t know where to start. - Dmitry Nail
  • @ Dmitry Gvozd, in this question I described a class wrapper over Bitmap. GetPixel wrapper worked faster than Bitmap. - Vlad
  • You can pre-make screenshots in black and white, then when comparing, if there are no differences, then the first case, otherwise the second. - Isaev

1 answer 1

You can try this

static bool Equality(Bitmap Bmp1, Bitmap Bmp2) { var pixelTrue = 0.0; var pixelFalse = 0.0; if (Bmp1.Size == Bmp2.Size) { for (int i = 0; i < Bmp1.Width; i++) for (int j = 0; j < Bmp1.Height; j++) { var pixel1 = Bmp1.GetPixel(i, j); var pixel2 = Bmp2.GetPixel(i, j); if (pixel1 != pixel2) pixelFalse++; else pixelTrue++; } } else return false; var percentResult = (pixelTrue/(pixelTrue + pixelFalse))*100; return percentResult >= 97; } 

Although the step can be increased!

  • 2
    GetPixel is a very slow operation. It is much better to get Scan0 and compare 2 arrays. And the idea with PixelFormat.Format1bppIndexed is something suspicious. - Qwertiy
  • @Qwertiy yes Clone is not needed here. I didn’t even know that this is possible, if not difficult, can you give an example of how to determine color using Scan0? - Yury Bakharev
  • 2
    cyberforum.ru/post5548691.html - something like that (deploy a spoiler with the code there). And now: cyberforum.ru/post5551672.html - Qwertiy