示例#1
0
        static Bitmap CaptureFromScreen(IntPtr hwnd, WindowInfo wi)
        {
            using (var guard = new ForegroundWindowGuard()) {
                if (guard.ForegroundWindow != hwnd)
                {
                    Utils.ForceForegroundWindow(hwnd);
                }

                Bitmap windowBitmap = new Bitmap(
                    wi.rcWindow.right - wi.rcWindow.left,
                    wi.rcWindow.bottom - wi.rcWindow.top,
                    System.Drawing.Imaging.PixelFormat.Format32bppRgb
                    );

                Graphics graphicsWindow = Graphics.FromImage(windowBitmap);

                graphicsWindow.CopyFromScreen(
                    new Point(wi.rcWindow.left, wi.rcWindow.top),
                    Point.Empty,
                    windowBitmap.Size,
                    CopyPixelOperation.SourceCopy
                    );

                return(windowBitmap);
            }
        }
        static Bitmap CaptureFromScreen(IntPtr hwnd, WindowInfo wi)
        {
            using (var guard = new ForegroundWindowGuard()) {
                if (guard.ForegroundWindow != hwnd)
                    Utils.ForceForegroundWindow(hwnd);

                Bitmap windowBitmap = new Bitmap(
                    wi.rcWindow.right - wi.rcWindow.left,
                    wi.rcWindow.bottom - wi.rcWindow.top,
                    System.Drawing.Imaging.PixelFormat.Format32bppRgb
                );

                Graphics graphicsWindow = Graphics.FromImage(windowBitmap);

                graphicsWindow.CopyFromScreen(
                    new Point(wi.rcWindow.left, wi.rcWindow.top),
                    Point.Empty,
                    windowBitmap.Size,
                    CopyPixelOperation.SourceCopy
                );

                return windowBitmap;
            }
        }