如何比较 PictureBox 和资源数据之间的两个图像?
How to compare two images between a PictureBox and a resource data?
所以我有一个图片框,我需要检查它当前显示的是什么图像,以便我可以将它放在 if 语句中。
基本上“如果 pictureBox1 图像是菱形那么做”。我在图片框中使用的所有图像都在资源中。
我尝试了 if(pictureBox1.Image == Properties.Resources.diamond){}
之类的方法,但似乎不起作用。
使用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 )
{
...
}
还有:How to compare two images?
所以我有一个图片框,我需要检查它当前显示的是什么图像,以便我可以将它放在 if 语句中。
基本上“如果 pictureBox1 图像是菱形那么做”。我在图片框中使用的所有图像都在资源中。
我尝试了 if(pictureBox1.Image == Properties.Resources.diamond){}
之类的方法,但似乎不起作用。
使用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 )
{
...
}
还有:How to compare two images?