-4

I have issue in my code, it doesn't works, look at code: What is wrong? I've found this:

if (pictureBox1.Image.Equals(Q))
{
    --stav;
}

It should do something like this

if (pictureBox1.Image == ProjectName.Properties.Resources.Q)
{

}

My question is, how to make something like if (pictureBox1.Image == ProjectName.....) Thanks

PROBLEM SOLVED!

Sam
  • 13
  • 6

1 Answers1

1

Resources.SomeProperty lets say SomeProperty is an Image will always return a new instance. So they are different references.

Image class doesn't overloads == operator. So == will result in Reference comparison, which is never going to be true for different references.

Image.Equals method also won't work as it doesn't override Equals so once again Reference comparison will be used.

You need your own Image comparison algorithm if you need to compare it. You'd do it by comparing pixel by pixel.

Sriram Sakthivel
  • 72,067
  • 7
  • 111
  • 189
  • I don't want to compare image, i want to compare image source. ex. compare if right now used image (compare as file address) is same as ProjectName.Properties.Resources.Image Got it? I want to compare file path. Not pixel by pixel. – Sam Aug 25 '14 at 15:19
  • What does that even mean? When you have `Image` object alone you can't find where does it comes from. Can you explain some more what you're trying to achieve? – Sriram Sakthivel Aug 25 '14 at 15:20
  • `ProjectName.Properties.Resources.Image` is not a file path. It is also a property which returns `Image`. That is also a object. My answer still stands, If you want to compare which images you need to compare pixel by pixel only. Another workaround will be store the name of the property you get the image in a string field, then you can check that string field to see where you got the image. Otherwise you can't do that. There is no way to find where you got the `Image` object from. – Sriram Sakthivel Aug 25 '14 at 15:26
  • [link] http://i.epvpimg.com/4Frie.png [/link] – Sam Aug 25 '14 at 15:33
  • So how can i compare if image used by pictureBox1 is image from resources? Another way than pixel by pixel? Please briefly. – Sam Aug 25 '14 at 15:35