andrE
andrE

Reputation: 25

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

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.

Upvotes: 2

Views: 777

Answers (1)

user12031933
user12031933

Reputation:

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?

Upvotes: 2

Related Questions