Beispiel #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
            }
        }
Beispiel #2
0
        // From hBitmap.
        internal DirectBitmap(IntPtr hdcSrc, IntPtr hBitmap)
        {
            Gdi32.BITMAPINFO bmi = new Gdi32.BITMAPINFO();
            bmi.bmiHeader.biSize = (uint)Marshal.SizeOf(bmi.bmiHeader);
            Gdi32.GetDIBits(hdcSrc, hBitmap, 0, 0, null, ref bmi, Gdi32.DIB_Color_Mode.DIB_RGB_COLORS);

            Bytes = new byte[bmi.bmiHeader.biSizeImage];

            bmi.bmiHeader.biBitCount    = 32;
            bmi.bmiHeader.biCompression = Gdi32.BitmapCompressionMode.BI_RGB;
            bmi.bmiHeader.biHeight      = Math.Abs(bmi.bmiHeader.biHeight);
            Gdi32.GetDIBits(hdcSrc, hBitmap, 0, (uint)bmi.bmiHeader.biHeight,
                            Bytes, ref bmi, Gdi32.DIB_Color_Mode.DIB_RGB_COLORS);

            Width        = bmi.bmiHeader.biWidth;
            Height       = bmi.bmiHeader.biHeight;
            BytesPerLine = Width * 4;

            Inverted = true;
        }
Beispiel #3
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
            }
        }
Beispiel #4
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();
        }