I know 3 ways to compare byte array:
- byte[].SequenceEqual(byte[])
- System.Text.Encoding.UTF8.GetString(byte[]) ==
- Convert.ToBase64String(byte[]) ==
For your code you can easy try this:
Console.WriteLine("SEQUENCE EQUAL: " + (HashImage(im1).SequenceEqual(HashImage(im2)) ? "TRUE" : "FALSE") + " (easiest way)");
Console.WriteLine("UTF8 STRING: " + (System.Text.Encoding.UTF8.GetString(HashImage(im1)) == System.Text.Encoding.UTF8.GetString(HashImage(im2)) ? "TRUE" : "FALSE") + " (conversion to utf string - not good for display or hash, good only for data from UTF8 range)");
Console.WriteLine("HASH STRING: " + (Convert.ToBase64String(HashImage(im1)) == Convert.ToBase64String(HashImage(im2)) ? "TRUE" : "FALSE") + " (best to display)");
Console.WriteLine("1: " + Convert.ToBase64String(HashImage(im1)));
Console.WriteLine("2: " + Convert.ToBase64String(HashImage(im2)));
Add this to your code right after initialization of Bitmap im2, and look at results in output window. You can use any of this for compare and evaluate if array is the same.
Note: System.Text.Encoding.UTF8.GetString
is not suitable for use in this case (hash data from picture). See comment from @CodesInChaos below.