title: How do I compare if 2 images are the same using Hash bytes?
body: <pre><code>private void button1_Click(object sender, EventArgs e)
  {
      Bitmap im1 = new Bitmap(@"C:\Users\user\Downloads\CaptchaCollection\1.png");
      Bitmap im2 = new Bitmap(@"C:\Users\user\Downloads\CaptchaCollection\2.png");
  
      if (HashImage(im1) == HashImage(im2))
      {
          MessageBox.Show("Same Image");
      }
  
      else
      {
          MessageBox.Show("Different Image");
      }
  }
  </code></pre>
  
  <p>If the button is clicked it will compare these 2 images.</p>
  
  <p>Here is the code that is used to hash an image.</p>
  
  <pre><code>public byte[] HashImage(Bitmap image)
  {
      var sha256 = SHA256.Create();
  
      var rect = new Rectangle(0, 0, image.Width, image.Height);
      var data = image.LockBits(rect, ImageLockMode.ReadOnly, image.PixelFormat);
  
      var dataPtr = data.Scan0;
  
      var totalBytes = (int)Math.Abs(data.Stride) * data.Height;
      var rawData = new byte[totalBytes];
      System.Runtime.InteropServices.Marshal.Copy(dataPtr, rawData, 0, totalBytes);
  
      image.UnlockBits(data);
  
      return sha256.ComputeHash(rawData);
  }
  </code></pre>
  
  <p>So how do I use the <code>HashImage()</code> method to compare both those images if they're the same visually or not?</p>
  
  <p>I tried comparing 2 images that are clearly the same but they aren't working to compare correctly. Instead I'm getting as if it's a different image.</p>
  
  <p>I even tried this but it's not working either.</p>
  
  <pre><code>if (HashImage(im1).Equals(HashImage(im2)))
  </code></pre>
  
  <p>UPDATE: I've tried this but it isn't working either.</p>
  
  <pre><code>if (ReferenceEquals(HashImage(im1),HashImage(im2)))
  </code></pre>