Home > Backend Development > C#.Net Tutorial > C# A quick way to determine whether two pictures are consistent

C# A quick way to determine whether two pictures are consistent

黄舟
Release: 2017-01-19 10:37:16
Original
2276 people have browsed it

C# A quick method to determine whether two pictures are consistent

#region 判断图片是否一致   
/// <summary>   
/// 判断图片是否一致   
/// </summary>   
/// <param name="img">图片一</param>   
/// <param name="bmp">图片二</param>   
/// <returns>是否一致</returns>   
public bool IsSameImg(Bitmap img, Bitmap bmp)   
{   
//大小一致   
if (img.Width == bmp.Width && img.Height == bmp.Height)   
{   
//将图片一锁定到内存   
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);   
//将图片二锁定到内存   
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);   
//长度不相同   
if (length_i != length_b)   
{   
return false;   
}   
else   
{   
//循环判断值   
for (int i = 0; i < length_i; i++)   
{   
//不一致   
if (imgValue_i[i] != imgValue_b[i])   
{   
return false;   
}   
}   
return true;   
}   
}   
else   
{   
return false;   
}   
}   
#endregion
Copy after login


The above is the content of C#’s quick method to determine whether two pictures are consistent. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Related labels:
c#
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template