title: Captured screen & conversion to Byte[] (image comparison methods)
body: <p>I've red a few posts regarding image comparison, and I tried to save image captured from screen then store it in file system .</p>
  
  <p>I used conversion methods to convert captured image into <code>byte[]</code> for later use .</p>
  
  <p>Then when I want to compare it to second screen capture, I load (file saved into <code>byte[]</code>) and  compare it against new capture that converted into <code>byte[]</code> in the same way.</p>
  
  <p>Now when having both 1st capture and 2nd capture, in memory, there was few ways to do the comparison, I wanted firstly to share this post with others searching for the same answer and for me to know : </p>
  
  <p>Which is faster, and how do I control the percentage of the similarity?</p>
  
  <p>If the option to have percentage (of equality) is opposing the fastest way to compute...
  I can disregard it,  although I could use it in other projects when performance issue is not there, and according to its needs</p>
  
  <p>These are the codes I know available to do the task </p>
  
  <p>I wanted to check with you for ideas which is faster and if there's a better way at all with and without equality percentage. Thank you.</p>
  
  <pre><code>static bool ByteArrayCompare(byte[] a1, byte[] a2)
  {     
    IStructuralEquatable eqa1 = a1;     
    return eqa1.Equals(a2, StructuralComparisons.StructuralEqualityComparer); 
  } 
  </code></pre>
  
  <p>vs</p>
  
  <pre><code>public enum CompareResult
  {
    ciCompareOk,
    ciPixelMismatch,
    ciSizeMismatch
  };
  
  CompareResult cr = CompareResult.ciCompareOk;
  
  byte[] hash1 = shaM.ComputeHash(btImage1);
  byte[] hash2 = shaM.ComputeHash(btImage2);
  
  //Compare the hash values
  for (int i = 0; i &lt; hash1.Length &amp;&amp; i &lt; hash2.Length 
                    &amp;&amp; cr == CompareResult.ciCompareOk; i++)
  {
      if (hash1[i] != hash2[i])
          cr = CompareResult.ciPixelMismatch;
  }
  </code></pre>
  
  <p>the later is using <code>System.Security.Cryptography</code></p>