Exemple #1
0
 //清屏
 private static void Cleanup(int hBitmap, int hdcSrc, int hdcDest)
 {
     User32.ReleaseDC(User32.GetDesktopWindow(), hdcSrc);
     GDI32.DeleteDC(hdcDest);
     GDI32.DeleteObject(hBitmap);
 }
Exemple #2
0
        //抓屏
        public static void CaptureScreenNow(string filePath)
        {
            int hdcSrc  = User32.GetWindowDC(User32.GetDesktopWindow()),
                hdcDest = GDI32.CreateCompatibleDC(hdcSrc),
                hBitmap = GDI32.CreateCompatibleBitmap(hdcSrc,
                                                       GDI32.GetDeviceCaps(hdcSrc, 8), GDI32.GetDeviceCaps(hdcSrc, 10)); GDI32.SelectObject(hdcDest, hBitmap);

            GDI32.BitBlt(hdcDest, 0, 0, GDI32.GetDeviceCaps(hdcSrc, 8),
                         GDI32.GetDeviceCaps(hdcSrc, 10), hdcSrc, 0, 0, 0x00CC0020);
            SaveImageAs(hBitmap, filePath, ImageFormat.Jpeg);
            Cleanup(hBitmap, hdcSrc, hdcDest);
        }