日期:2014-05-18 浏览次数:20790 次
public static Bitmap GetDesktop() { int screenX; int screenY; IntPtr hBmp; IntPtr hdcScreen = GetDC(GetDesktopWindow()); IntPtr hdcCompatible = CreateCompatibleDC(hdcScreen); screenX = GetSystemMetrics(0); screenY = GetSystemMetrics(1); hBmp = CreateCompatibleBitmap(hdcScreen, screenX, screenY); if (hBmp != IntPtr.Zero) { IntPtr hOldBmp = (IntPtr)SelectObject(hdcCompatible, hBmp); BitBlt(hdcCompatible, 0, 0, screenX, screenY, hdcScreen, 0, 0, 13369376); SelectObject(hdcCompatible, hOldBmp); DeleteDC(hdcCompatible); ReleaseDC(GetDesktopWindow(), hdcScreen); Bitmap bmp = System.Drawing.Image.FromHbitmap(hBmp); DeleteObject(hBmp); GC.Collect(); return bmp; }