C # Quick Method for Determining whether two images are consistent

Source: Internet
Author: User

Copy codeThe Code is as follows:
# Region determine whether the image is consistent
/// <Summary>
/// Determine whether the image is consistent
/// </Summary>
/// <Param name = "img"> image 1 </param>
/// <Param name = "bmp"> Image 2 </param>
/// <Returns> consistency </returns>
Public bool IsSameImg (Bitmap img, Bitmap bmp)
{
// Consistent size
If (img. Width = bmp. Width & img. Height = bmp. Height)
{
// Lock image 1 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 Image 2 to the 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 );
// The length is different.
If (length_ I! = Length_ B)
{
Return false;
}
Else
{
// Cyclic judgment Value
For (int I = 0; I <length_ I; I ++)
{
// Inconsistent
If (imgValue_ I [I]! = ImgValue_ B [I])
{
Return false;
}
}
Return true;
}
}
Else
{
Return false;
}
}
# 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.