.NET GDI+提供了比GDI更好的封装,但是它对底层操作的屏蔽导致我们无法用它来实现位图的运算,比如与(SRCAND)、或(SRCPAINT)、异或(SRCINVERT)等方式的贴图。为了实现这些样式的贴图,我们不得不调用GDI。
首先加入下面两行代码,它指明了我们会用到微软的非托管dll的函数:
using System.Runtime.InteropServices;
using System.Reflection;
下面,我们声明一些GDI函数。由于以前有过使用GDI进行开发的经历,所以很容易想到应该用到的一些函数:SelectObject、DeleteObject、CreateCompatibleDC、DeleteDC、BitBlt等等。
[DllImport("gdi32.dll")]
static public extern IntPtr CreateCompatibleDC(IntPtr hDC);
[DllImport("gdi32.dll",EntryPoint="BitBlt")]
public static extern bool BitBlt(IntPtr hdcDest,int nXDest,
int nYDest,int nWidth,int nHeight,IntPtr hdcSrc,
int nXSrc,int nYSrc,int dwRop);
[DllImport("user32.dll",EntryPoint="GetDC")]
public static extern IntPtr GetDC(IntPtr hWnd);
[DllImport("gdi32.dll")]
public static