From 635aa484a7e3986b62587b5a400a5a993d29304f Mon Sep 17 00:00:00 2001 From: "Valeriano A.R" Date: Sat, 9 Apr 2022 16:29:28 +0200 Subject: [PATCH] Remove duplicated Screenshoter --- VAR.Toolbox/Code/Bots/Screenshoter.cs | 51 ------------------- VAR.Toolbox/Code/Screenshoter.cs | 39 ++++++++++---- .../ScreenAutomation/FrmScreenAutomation.cs | 1 - VAR.Toolbox/VAR.Toolbox.csproj | 1 - 4 files changed, 29 insertions(+), 63 deletions(-) delete mode 100644 VAR.Toolbox/Code/Bots/Screenshoter.cs diff --git a/VAR.Toolbox/Code/Bots/Screenshoter.cs b/VAR.Toolbox/Code/Bots/Screenshoter.cs deleted file mode 100644 index 8003614..0000000 --- a/VAR.Toolbox/Code/Bots/Screenshoter.cs +++ /dev/null @@ -1,51 +0,0 @@ -using System; -using System.Drawing; -using System.Windows.Forms; - -namespace VAR.ScreenAutomation.Code -{ - public static class Screenshoter - { - public static Bitmap CaptureControl(Control ctrl, Bitmap bmp = null) - { - if (ctrl == null) { return bmp; } - - Point picCapturerOrigin = ctrl.PointToScreen(new Point(0, 0)); - bmp = CaptureScreen(bmp, picCapturerOrigin.X, picCapturerOrigin.Y, ctrl.Width, ctrl.Height); - return bmp; - } - - private static Bitmap CaptureScreen(Bitmap bmp = null, int? left = null, int? top = null, int? width = null, - int? height = null) - { - if (width <= 0 || height <= 0) { return bmp; } - - // Determine the size of the "virtual screen", which includes all monitors. - left = left ?? SystemInformation.VirtualScreen.Left; - top = top ?? SystemInformation.VirtualScreen.Top; - width = width ?? SystemInformation.VirtualScreen.Width; - height = height ?? SystemInformation.VirtualScreen.Height; - - // Create a bitmap of the appropriate size to receive the screenshot. - if (bmp == null || bmp.Width != width || bmp.Height != height) - { - bmp = new Bitmap((int)width, (int)height); - } - - try - { - // Draw the screenshot into our bitmap. - using (Graphics g = Graphics.FromImage(bmp)) - { - g.CopyFromScreen((int)left, (int)top, 0, 0, bmp.Size); - } - } - catch (Exception) - { - /* Nom Nom Nom */ - } - - return bmp; - } - } -} \ No newline at end of file diff --git a/VAR.Toolbox/Code/Screenshoter.cs b/VAR.Toolbox/Code/Screenshoter.cs index 07b4468..bd9f067 100644 --- a/VAR.Toolbox/Code/Screenshoter.cs +++ b/VAR.Toolbox/Code/Screenshoter.cs @@ -8,24 +8,43 @@ namespace VAR.Toolbox.Code { public static class Screenshoter { - public static Bitmap CaptureScreen(Bitmap bmp = null) + public static Bitmap CaptureControl(Control ctrl, Bitmap bmp = null) { + if (ctrl == null) { return bmp; } + + Point picCapturerOrigin = ctrl.PointToScreen(new Point(0, 0)); + bmp = CaptureScreen(bmp, picCapturerOrigin.X, picCapturerOrigin.Y, ctrl.Width, ctrl.Height); + return bmp; + } + + public static Bitmap CaptureScreen(Bitmap bmp = null, int? left = null, int? top = null, int? width = null, + int? height = null) + { + if (width <= 0 || height <= 0) { return bmp; } + // Determine the size of the "virtual screen", which includes all monitors. - int screenLeft = SystemInformation.VirtualScreen.Left; - int screenTop = SystemInformation.VirtualScreen.Top; - int screenWidth = SystemInformation.VirtualScreen.Width; - int screenHeight = SystemInformation.VirtualScreen.Height; + left = left ?? SystemInformation.VirtualScreen.Left; + top = top ?? SystemInformation.VirtualScreen.Top; + width = width ?? SystemInformation.VirtualScreen.Width; + height = height ?? SystemInformation.VirtualScreen.Height; // Create a bitmap of the appropriate size to receive the screenshot. - if (bmp == null || bmp.Width != screenWidth || bmp.Height != screenHeight) + if (bmp == null || bmp.Width != width || bmp.Height != height) { - bmp = new Bitmap(screenWidth, screenHeight); + bmp = new Bitmap((int)width, (int)height); } - // Draw the screenshot into our bitmap. - using (Graphics g = Graphics.FromImage(bmp)) + try { - g.CopyFromScreen(screenLeft, screenTop, 0, 0, bmp.Size); + // Draw the screenshot into our bitmap. + using (Graphics g = Graphics.FromImage(bmp)) + { + g.CopyFromScreen((int)left, (int)top, 0, 0, bmp.Size); + } + } + catch (Exception) + { + /* Nom Nom Nom */ } return bmp; diff --git a/VAR.Toolbox/UI/Tools/ScreenAutomation/FrmScreenAutomation.cs b/VAR.Toolbox/UI/Tools/ScreenAutomation/FrmScreenAutomation.cs index 865cb8d..0d414eb 100644 --- a/VAR.Toolbox/UI/Tools/ScreenAutomation/FrmScreenAutomation.cs +++ b/VAR.Toolbox/UI/Tools/ScreenAutomation/FrmScreenAutomation.cs @@ -9,7 +9,6 @@ using VAR.Toolbox.Code.Bots; using VAR.Toolbox.Code.Configuration; using VAR.Toolbox.Controls; using Mouse = VAR.ScreenAutomation.Code.Mouse; -using Screenshoter = VAR.ScreenAutomation.Code.Screenshoter; // ReSharper disable LocalizableElement diff --git a/VAR.Toolbox/VAR.Toolbox.csproj b/VAR.Toolbox/VAR.Toolbox.csproj index e8c1f53..71f9fc7 100644 --- a/VAR.Toolbox/VAR.Toolbox.csproj +++ b/VAR.Toolbox/VAR.Toolbox.csproj @@ -79,7 +79,6 @@ -