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
| class XorFilter : IFilter
{
public void Process(Point pos, Graphics dest, Bitmap src)
{
IntPtr dst = dest.GetHdc();
IntPtr source=CreateCompatibleDC(dst);
IntPtr org=SelectObject(source,src.GetHbitmap());
UInt32 dwrop = 0x00660046;//srcinvert
BitBlt(dst, pos.X, pos.Y, src.Width, src.Height, source, 0, 0, dwrop);
IntPtr n = SelectObject(source, org);
DeleteObject(n);
DeleteDC(source);
dest.ReleaseHdc(dst);
}
[DllImport("gdi32.dll")]
private static extern bool BitBlt(IntPtr hdcDest,
Int32 nXDest,
Int32 nYDest,
Int32 nWidth,
Int32 nHeight,
IntPtr hdcSrc,
Int32 nXSrc,
Int32 nYSrc,
UInt32 dwRop);
[DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]
static extern IntPtr CreateCompatibleDC(IntPtr hdc);
[DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]
static extern bool DeleteDC(IntPtr hdc);
[DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]
static extern IntPtr SelectObject(IntPtr hdc, IntPtr hgdiobj);
[DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]
static extern bool DeleteObject(IntPtr hObject);
} |
Partager