示例#1
0
        private static void ScreenshotBitBlt(IntPtr hWnd, ref DirectBitmap capture)
        {
            try
            {
                // get the hDC of the target window
                IntPtr hdcSrc = User32.GetDC(hWnd);
                // get the size
                Rectangle windowRect = new Rectangle();
                User32.GetWindowRect(hWnd, ref 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 to 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, 1, 31, width - 10, height, hdcSrc, 0, 0, (uint)Gdi32.TernaryRasterOperations.SRCCOPY | (uint)Gdi32.TernaryRasterOperations.CAPTUREBLT);
                // restore selection
                Gdi32.SelectObject(hdcDest, hOld);

                if (capture != null)
                {
                    capture.Dispose();
                }
                capture = new DirectBitmap(hdcSrc, hBitmap);

                // clean up
                Gdi32.DeleteDC(hdcDest);
                User32.ReleaseDC(hWnd, hdcSrc);
                // free up the Bitmap object
                Gdi32.DeleteObject(hBitmap);
            }
            catch (ExternalException)
            {
                // Failed to capture window, usually because it was closed.
#if DEBUG
                CustomGameDebug.WriteLine("Failed to capture window. Is it closed?");
#endif
            }
        }
示例#2
0
        private void ScreenshotBitBlt()
        {
            try
            {
                // get the hDC of the target window
                IntPtr hdcSrc = User32.GetDC(OverwatchHandle);
                // get the size
                int width  = Rectangles.ENTIRE_SCREEN.Width + Points.BITBLT_WINDOW_LOCATION.X;
                int height = Rectangles.ENTIRE_SCREEN.Height + Points.BITBLT_WINDOW_LOCATION.Y;
                // create a device context we can copy to
                IntPtr hdcDest = Gdi32.CreateCompatibleDC(hdcSrc);
                // create a bitmap we can copy it to,
                // using GetDeviceCaps to 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, Points.BITBLT_WINDOW_LOCATION.X, Points.BITBLT_WINDOW_LOCATION.Y, width, height, hdcSrc, 0, 0, (uint)Gdi32.TernaryRasterOperations.SRCCOPY | (uint)Gdi32.TernaryRasterOperations.CAPTUREBLT);
                // restore selection
                Gdi32.SelectObject(hdcDest, hOld);

                if (Capture != null)
                {
                    Capture.Dispose();
                }
                Capture = new DirectBitmap(hdcSrc, hBitmap);

                // clean up
                Gdi32.DeleteDC(hdcDest);
                User32.ReleaseDC(OverwatchHandle, hdcSrc);
                // free up the Bitmap object
                Gdi32.DeleteObject(hBitmap);
            }
            catch (ExternalException)
            {
                // Failed to capture window, usually because it was closed.
#if DEBUG
                CustomGameDebug.WriteLine("Failed to capture window. Is it closed?");
#endif
            }
        }
示例#3
0
        static void ScreenshotBitBlt(IntPtr hWnd, ref Bitmap bmp, bool adjust = true)
        {
            // get the hDC of the target window
            IntPtr hdcSrc = User32.GetDC(hWnd);
            // get the size
            Rectangle windowRect = new Rectangle();

            User32.GetWindowRect(hWnd, ref 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 to 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, 1, 31, width - 10, height, hdcSrc, 0, 0, (uint)Gdi32.TernaryRasterOperations.SRCCOPY | (uint)Gdi32.TernaryRasterOperations.CAPTUREBLT);
            // restore selection
            Gdi32.SelectObject(hdcDest, hOld);
            // clean up
            Gdi32.DeleteDC(hdcDest);
            User32.ReleaseDC(hWnd, hdcSrc);
            // get a .NET image object for it
            Image img = Image.FromHbitmap(hBitmap);

            // free up the Bitmap object
            Gdi32.DeleteObject(hBitmap);

            if (bmp != null)
            {
                bmp.Dispose();
            }
            bmp = new Bitmap(img);
            img.Dispose();
        }