/// <summary> /// Shows an overlay over the screen that allows the user to select a /// region, of which the image is captured and returned. /// </summary> /// <returns>A <see cref="Screenshot"/> with the selected region.</returns> public static Screenshot FromRegion() { try { Screenshot screenshot = new Screenshot(); screenshot.Source = ScreenshotSource.RegionCapture; RegionOverlay overlay = new RegionOverlay(); if (overlay.ShowDialog() == DialogResult.OK) { Rectangle rect = overlay.SelectedRegion; if (rect.Width > 0 && rect.Height > 0) { screenshot.Bitmap = new Bitmap(rect.Width, rect.Height); using (Graphics g = Graphics.FromImage(screenshot.Bitmap)) { g.Clear(ThatFuckingColor); g.CopyFromScreen(rect.X, rect.Y, 0, 0, new Size(rect.Width, rect.Height), CopyPixelOperation.SourceCopy); } return(screenshot); } } } catch (Exception ex) { Trace.WriteLine(ex); System.Media.SystemSounds.Exclamation.Play(); } return(null); }
/// <summary> /// Shows an overlay over the screen that allows the user to select a /// region, of which the image is captured and returned. /// </summary> /// <returns>A <see cref="Screenshot"/> with the selected region.</returns> public static Screenshot FromRegion() { try { Screenshot screenshot = new Screenshot(); screenshot.Source = ScreenshotSource.RegionCapture; RegionOverlay overlay = new RegionOverlay(); if (overlay.ShowDialog() == DialogResult.OK) { Rectangle rect = overlay.SelectedRegion; if (rect.Width > 0 && rect.Height > 0) { screenshot.Bitmap = new Bitmap(rect.Width, rect.Height); using (Graphics g = Graphics.FromImage(screenshot.Bitmap)) { g.Clear(ThatFuckingColor); g.CopyFromScreen(rect.X, rect.Y, 0, 0, new Size(rect.Width, rect.Height), CopyPixelOperation.SourceCopy); } return screenshot; } } } catch (Exception ex) { Trace.WriteLine(ex); System.Media.SystemSounds.Exclamation.Play(); } return null; }