【问题标题】:How to compare two images between a PictureBox and a resource data?如何比较 PictureBox 和资源数据之间的两个图像?
【发布时间】:2020-07-04 01:04:31
【问题描述】:

所以我有一个图片框,我需要检查它当前显示的是什么图像,以便我可以将它放入 if 语句中。 基本上“如果 pictureBox1 图像是菱形,那么就做”。我在图片框中使用的所有图像都在资源中。 我尝试了类似if(pictureBox1.Image == Properties.Resources.diamond){} 的方法,但这似乎不起作用。

【问题讨论】:

标签: c# image winforms compare picturebox


【解决方案1】:

使用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?

【讨论】:

  • 完美!非常感谢!这解决了我的问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-03
相关资源
最近更新 更多