Пример #1
0
        /// <summary>
        /// NOT WORKING WITH WARFRAME ATM. Creates an Image object containing a screen shot of a specific window
        /// </summary>
        /// <param name="handle">The handle to the window. (In windows forms, this is obtained by the Handle property)</param>
        /// <returns>The captured image</returns>
        public static Image CaptureWindow(IntPtr handle)
        {
            // get te hDC of the target window
            IntPtr hdcSrc = ProcessWindowHelper.GetWindowDC(handle);

            // get the size
            ProcessWindowHelper.GetWindowRect(handle, out ProcessWindowHelper.RECT windowRect);
            int width  = windowRect.Right - windowRect.Left;
            int height = windowRect.Bottom - windowRect.Top;
            // create a device context we can copy to
            IntPtr hdcDest = GDI32.CreateCompatibleDC(hdcSrc);
            // create a bitmap we can copy it to,
            // using GetDeviceCaps t1o get the width/height
            IntPtr hBitmap = GDI32.CreateCompatibleBitmap(hdcSrc, width, height);
            // select the bitmap object
            IntPtr hOld = GDI32.SelectObject(hdcDest, hBitmap);

            // bitblt over
            GDI32.BitBlt(hdcDest, 0, 0, width, height, hdcSrc, 0, 0, GDI32.SRCCOPY);
            // restore selection
            GDI32.SelectObject(hdcDest, hOld);
            // clean up
            GDI32.DeleteDC(hdcDest);
            ProcessWindowHelper.ReleaseDC(handle, hdcSrc);
            // get a .NET image object for it
            Image img = Image.FromHbitmap(hBitmap);

            // free up the Bitmap object
            GDI32.DeleteObject(hBitmap);
            return(img);
        }
Пример #2
0
 /// <summary>
 /// Creates an Image object containing a screen shot of the entire desktop
 /// </summary>
 /// <returns></returns>
 public static Image CaptureScreen()
 {
     return(CaptureWindow(ProcessWindowHelper.GetDesktopWindow()));
 }