C # Quick way to determine whether two pictures are consistent

Source: Internet
Author: User

  This article mainly introduces C # to determine whether two pictures are consistent fast method, the need for friends can refer to the following

The code is as follows: #region to determine whether the picture is consistent  ///<summary> ///to determine whether the picture is consistent  ///</summary> ///<param name= " IMG "> Picture one </param> ///<param name=" BMP "> Picture two </param> ///<returns> is consistent </ returns>  public bool Issameimg (Bitmap img, Bitmap BMP)   { //size consistent   if (IMG. Width = = bmp. Width && img. Height = = bmp. Height)   { //Lock picture one to memory   BitmapData imgdata_i = img. LockBits (New Rectangle (0, 0, IMG). Width, IMG. Height), imagelockmode.readonly, Pixelformat.format24bpprgb);  IntPtr ipr_i = imgdata_i.scan0;  int length_i = Imgdata_i.width * Imgdata_i.height * 3;  byte[] imgvalue_i = new byte[length_i];  Marshal.Copy (Ipr_i, ImgValue _i, 0, length_i);  img. Unlockbits (imgdata_i); //Lock picture two to memory   BitmapData imgdata_b = img. LockBits (New Rectangle (0, 0, IMG). Width, IMG. Height), imagelockmode.readonly, Pixelformat.format24bpprgb);  IntPtr ipr_b = imgdata_b.scan0;  int Length_b =Imgdata_b.width * imgdata_b.height * 3;  byte[] imgvalue_b = new byte[length_b];  Marshal.Copy (Ipr_b, ImgValue_ B, 0, Length_b);  img. Unlockbits (Imgdata_b); //Length not identical   if (length_i!= length_b)   {  return false; }  Else   { //Cycle judgment   for (int i = 0; i < length_i i++)   { /Inconsistent   if (imgvalue_i[i)!= Imgvalue _b[i])   {  return false; } }  return true; } }  else -{  return Fals e; } }  #endregion    

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.