public static void CaptureFullscreen(bool captureMouse, ScreenCaptureMode screenCaptureMode) { using (CaptureHelper captureHelper = new CaptureHelper(CaptureMode.FullScreen, captureMouse)) { captureHelper._screenCaptureMode = screenCaptureMode; captureHelper.MakeCapture(); } }
public static Bitmap Capture(int handle = 0, ScreenCaptureMode screenCaptureMode = ScreenCaptureMode.Window) { Rectangle bounds; var rect = new Rect(); if (screenCaptureMode == ScreenCaptureMode.Screen) { bounds = new Rectangle(int.MaxValue, int.MaxValue, int.MinValue, int.MinValue); foreach (Screen screen in Screen.AllScreens) bounds = Rectangle.Union(bounds, screen.Bounds); } else { IntPtr foregroundWindowsHandle = (IntPtr)handle; DateTime dateTime = DateTime.Now; while (foregroundWindowsHandle == (IntPtr)0) { if (DateTime.Now - dateTime > TimeSpan.FromSeconds(5)) { throw new Exception("Couldnt get the foreground window..."); } Thread.Sleep(100); foregroundWindowsHandle = GetForegroundWindow(); } GetWindowRect(foregroundWindowsHandle, ref rect); bounds = new Rectangle(rect.Left, rect.Top, rect.Right - rect.Left, rect.Bottom - rect.Top); //CursorPosition = new Point(Cursor.Position.X - rect.Left, Cursor.Position.Y - rect.Top); } var result = new Bitmap(bounds.Width, bounds.Height); using (var g = Graphics.FromImage(result)) { g.CopyFromScreen(new Point(bounds.Left, bounds.Top), Point.Empty, bounds.Size); return result; } }
/// <summary> /// Captures a full screen image of the screen. /// </summary> /// <param name="mode">The screen capture mode.</param> /// <returns>A screenshot object.</returns> public static Screenshot CaptureScreen(ScreenCaptureMode mode) { var screenshots = (from screen in Screen.AllScreens where mode != ScreenCaptureMode.Single || screen.Primary select CaptureScreenInternal(screen.Bounds)).ToList(); if (mode == ScreenCaptureMode.Single) { return(screenshots.FirstOrDefault()); } var totalWidth = screenshots.Sum(b => b.WorkingArea.Width); var totalHeight = screenshots.Select(b => b.WorkingArea.Height).FirstOrDefault(); var startX = screenshots.Select(b => b.WorkingArea.X).FirstOrDefault(); var startY = screenshots.Select(b => b.WorkingArea.Y).FirstOrDefault(); var bmp = new Bitmap(totalWidth, totalHeight, PixelFormat.Format32bppArgb); using (var gfx = Graphics.FromImage(bmp)) { foreach (var screenshot in screenshots) { gfx.DrawImage(screenshot.Image, screenshot.WorkingArea); } } // Dispose the old temporary screenshots); foreach (var screenshot in screenshots) { screenshot?.Dispose(); } return(new Screenshot { Image = bmp, WorkingArea = new Rectangle(startX, startY, totalWidth, totalHeight) }); }
public CaptureHelper(CaptureMode captureMode, bool captureMouseCursor, ScreenCaptureMode screenCaptureMode) : this(captureMode) { _captureMouseCursor = captureMouseCursor; _screenCaptureMode = screenCaptureMode; }
public static void CaptureFullscreen(bool captureMouse, ScreenCaptureMode screenCaptureMode) { new CaptureHelper(CaptureMode.FullScreen, captureMouse).MakeCapture(); }
public CaptureHelper(CaptureMode captureMode, bool captureMouseCursor, ScreenCaptureMode screenCaptureMode) : this(captureMode) { this.captureMouseCursor = captureMouseCursor; this.screenCaptureMode = screenCaptureMode; }