Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi, well i need to compare to images and iv found a way but was wondering if there is any faster way to do it.. any way here is my code:

 

public static bool CompareImage(Image img1, Image img2)
{
   //Test to see if we have the same size of image
   if (img1.Size != img2.Size)
   {
       return false;
   }
   else
   {
       //Convert each image to a byte array
       System.Drawing.ImageConverter ic =
              new System.Drawing.ImageConverter();
       byte[] btImage1 = new byte[1];
       btImage1 = (byte[])ic.ConvertTo(img1, btImage1.GetType());
       byte[] btImage2 = new byte[1];
       btImage2 = (byte[])ic.ConvertTo(img2, btImage2.GetType());
       

       for (int i = 0; i < btImage1.Length; i++)
       {
           if (btImage1[i] != btImage2[i])
           {
               return false;
           }
       }
   }
   return true;
}

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...