检查图片盒中的图像 [英] check image in picturebox
本文介绍了检查图片盒中的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨.
我需要检查图片框中的女巫图像.我写这段代码
Hi.
I need to check witch image in picture box. I write this code
if (Picturebox.Image == Application.Properties.Resources.cross)
但这行不通!请帮助我
But this not work! please help me
推荐答案
不会.
使用Properties.Resources.nameOfMyImage
时,它将根据Properties.Resources.nameOfMyImage
中的数据创建一个新的Image
并将其返回-因此,您正在比较的两个Image
对象使用不同的引用引用了Image的不同实例.由于相等运算符(对于大多数引用类型)仅比较引用,因此不会比较在这种情况下将始终失败的内容.
在static
构造函数中获取Property的静态副本,然后使用/比较它-这样便可以使用.
It won''t.
When you useProperties.Resources.nameOfMyImage
it creates a newImage
from the data inProperties.Resources.nameOfMyImage
and returns it - so the twoImage
objects you are comparing are referring to different instances of an Image with different references. Since the equality operator (for most reference types) compares only the reference, not the content it will always fail in these circumstances.
Take a static copy of the Property in astatic
constructor, and use / compare that - it will work then.
这篇关于检查图片盒中的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文