CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2007
    Posts
    448

    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.


    Code:
    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
    Location
    Germany
    Posts
    2,675

    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 http://msdn.microsoft.com/en-us/library/bsc2ak47.aspx) 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
  •  





Click Here to Expand Forum to Full Width

Featured