, , - 32bpp, 8bpp. , , LockBits 32bpp, Marshal.Copy(), , .
public static string PageCompare(string fname1, string fname2) {
try {
using (Bitmap bmp1 = new Bitmap(fname1))
using (Bitmap bmp2 = new Bitmap(fname2)) {
if (bmp1.Height != bmp2.Height || bmp1.Width != bmp2.Width)
return false;
int cnt = bmp1.Width * bmp1.Height * 4 / 4;
BitmapData bmData1 = bmp1.LockBits(new Rectangle(0, 0, bmp1.Width, bmp1.Height),
ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
BitmapData bmData2 = bmp2.LockBits(new Rectangle(0, 0, bmp2.Width, bmp2.Height),
ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
Int32[] rgbValues1 = new Int32[cnt];
Int32[] rgbValues2 = new Int32[cnt];
System.Runtime.InteropServices.Marshal.Copy(bmData1.Scan0, rgbValues1, 0, cnt);
System.Runtime.InteropServices.Marshal.Copy(bmData2.Scan0, rgbValues2, 0, cnt);
bmp1.UnlockBits(bmData1);
bmp2.UnlockBits(bmData2);
for (int i = 0; i < cnt; ++i) {
if (rgbValues1[i] != rgbValues2[i])
return false;
}
}
}
catch (Exception ex) {
return false;
}
return true;
}