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