how to check picturebox image?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 2 of 2

Thread: how to check picturebox image?

  1. #1
    Join Date
    Aug 2007

    how to check picturebox image?

    Hi All,

    I need your help. I have got a problem with the if statements. I want to check the picturebox through the resources as if the picturebox is reading the image called Image1, then display the messagebox.

    private: System::Void button1_Click_1(System::Object^  sender, System::EventArgs^  e) {
    			 ResourceManager^ resourceManager = gcnew ResourceManager("MyApplication1.myImages", GetType()->Assembly);
    			 Bitmap^ image = (Bitmap^)resourceManager->GetObject ("Image1");
    			 if (PictureBox1->Image->Equals(image))
    				 MessageBox::Show("image is correct");	 

    When I clicked on the button while the picturebox is reading the image, the messagebox doesn't display. Nothing have happened when I clicked on the button.

    Any idea?

  2. #2
    Join Date
    Jun 2010

    Re: how to check picturebox image?

    I'm not entirely sure what you actually want to achive here, but note that the Equals() implementation of Bitmap is the default implementation inherited from System::Object, and that just checks for reference equality. (See Therefore it will return true only if the two bitmap objects are really the same (i.e. identical), not if they just contain equivalent pixel data.

    Comparing the actual pixel data is not supported by any of the methods of the Bitmap class. Unless you use methods that are a bit advanced, it will probably be a time-consuming process (at least for bitmaps of considerable size). The easy way is comparing pixel by pixel using the Bitmap class' pixel accessor methods, but as I said that's really slow. And it gets even worse if you don't actually want to check for exact pixel-wise equality, because then you wouldn't need to check for equality but instead for similarity which, in particular for images, is a topic on its own that easily fills several books...

    However, there's one thing I can tell you for sure: It's no problem with the if instruction. This is most certainly working exactly as it should...
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)