Remove duplicated Screenshoter

This commit is contained in:
2022-04-09 16:29:28 +02:00
parent 9206ede6eb
commit 635aa484a7
4 changed files with 29 additions and 63 deletions

View File

@@ -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;
}
}
}

View File

@@ -8,24 +8,43 @@ namespace VAR.Toolbox.Code
{ {
public static class Screenshoter public static class Screenshoter
{ {
public static Bitmap CaptureScreen(Bitmap bmp = null) public static Bitmap CaptureControl(Control ctrl, Bitmap bmp = null)
{ {
// Determine the size of the "virtual screen", which includes all monitors. if (ctrl == null) { return bmp; }
int screenLeft = SystemInformation.VirtualScreen.Left;
int screenTop = SystemInformation.VirtualScreen.Top;
int screenWidth = SystemInformation.VirtualScreen.Width;
int screenHeight = SystemInformation.VirtualScreen.Height;
// Create a bitmap of the appropriate size to receive the screenshot. Point picCapturerOrigin = ctrl.PointToScreen(new Point(0, 0));
if (bmp == null || bmp.Width != screenWidth || bmp.Height != screenHeight) bmp = CaptureScreen(bmp, picCapturerOrigin.X, picCapturerOrigin.Y, ctrl.Width, ctrl.Height);
{ return bmp;
bmp = new Bitmap(screenWidth, screenHeight);
} }
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.
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. // Draw the screenshot into our bitmap.
using (Graphics g = Graphics.FromImage(bmp)) using (Graphics g = Graphics.FromImage(bmp))
{ {
g.CopyFromScreen(screenLeft, screenTop, 0, 0, bmp.Size); g.CopyFromScreen((int)left, (int)top, 0, 0, bmp.Size);
}
}
catch (Exception)
{
/* Nom Nom Nom */
} }
return bmp; return bmp;

View File

@@ -9,7 +9,6 @@ using VAR.Toolbox.Code.Bots;
using VAR.Toolbox.Code.Configuration; using VAR.Toolbox.Code.Configuration;
using VAR.Toolbox.Controls; using VAR.Toolbox.Controls;
using Mouse = VAR.ScreenAutomation.Code.Mouse; using Mouse = VAR.ScreenAutomation.Code.Mouse;
using Screenshoter = VAR.ScreenAutomation.Code.Screenshoter;
// ReSharper disable LocalizableElement // ReSharper disable LocalizableElement

View File

@@ -79,7 +79,6 @@
<Compile Include="Code\Bots\DummyBot.cs" /> <Compile Include="Code\Bots\DummyBot.cs" />
<Compile Include="Code\Bots\IAutomationBot.cs" /> <Compile Include="Code\Bots\IAutomationBot.cs" />
<Compile Include="Code\Bots\Mouse.cs" /> <Compile Include="Code\Bots\Mouse.cs" />
<Compile Include="Code\Bots\Screenshoter.cs" />
<Compile Include="Code\Bots\TetrisBot.cs" /> <Compile Include="Code\Bots\TetrisBot.cs" />
<Compile Include="Code\Configuration\FileBackedConfiguration.cs" /> <Compile Include="Code\Configuration\FileBackedConfiguration.cs" />
<Compile Include="Code\Configuration\IConfiguration.cs" /> <Compile Include="Code\Configuration\IConfiguration.cs" />