1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64:
| [DllImport("user32.dll")] static extern IntPtr GetDC(IntPtr hWnd);
[DllImport("gdi32.dll")] static extern int GetDIBits(IntPtr hdc, IntPtr hbmp, uint uStartScan, uint cScanLines, [Out] byte[] lpvBits, ref BITMAPINFO lpbmi, uint uUsage);
[StructLayout(LayoutKind.Sequential)] public struct BITMAPINFOHEADER { public uint biSize; public int biWidth; public int biHeight; public ushort biPlanes; public ushort biBitCount; public uint biCompression; public uint biSizeImage; public int biXPelsPerMeter; public int biYPelsPerMeter; public uint biClrUsed; public uint biClrImportant;
public void Init() { biSize = (uint)Marshal.SizeOf(this); } }
[StructLayout(LayoutKind.Sequential)] public struct BITMAPINFO { public Int32 biSize; public Int32 biWidth; public Int32 biHeight; public Int16 biPlanes; public Int16 biBitCount; public Int32 biCompression; public Int32 biSizeImage; public Int32 biXPelsPerMeter; public Int32 biYPelsPerMeter; public Int32 biClrUsed; public Int32 biClrImportant; }
public bool CompareBitmaps(IntPtr HBitmapLeft, IntPtr HBitmapRight) { if (HBitmapLeft == HBitmapRight) { return true; }
if (HBitmapLeft == IntPtr.Zero|| HBitmapRight == IntPtr.Zero) { return false; }
bool bSame = false;
IntPtr hdc = GetDC(IntPtr.Zero);
BITMAPINFO BitmapInfoLeft = new BITMAPINFO(); BITMAPINFO BitmapInfoRight = new BITMAPINFO();
BitmapInfoLeft.biSize = Marshal.SizeOf(BitmapInfoLeft); BitmapInfoRight.biSize = Marshal.SizeOf(BitmapInfoRight); |