How to compare two images between a PictureBox and a resource data?

Viewed 131

So I have a picturebox and I need to check what image it's currently displaying so I can put it in an if statement. Basically "if pictureBox1 image is diamond then do". All the images that I use in pictureboxes are in Resources. I tried something like if(pictureBox1.Image == Properties.Resources.diamond){} but that doesn't seem to work.

1 Answers

Using How to convert image to byte array :

var array1 = ImageToByteArray(pictureBox1.Image);
var array2 = ImageToByteArray(Properties.Resources.diamond);

bool isSame = array1.Length == array2.Length;

if ( isSame )
  for ( int index = 0; index < array1.Length; index++)
    if ( array1[index] != array2[index] )
    {
      isSame = false;
      break;
    }

if ( isSame )
{
  ...
}

Also : How to compare two images?

Related