Remove duplicated Screenshoter
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -79,7 +79,6 @@
|
||||
<Compile Include="Code\Bots\DummyBot.cs" />
|
||||
<Compile Include="Code\Bots\IAutomationBot.cs" />
|
||||
<Compile Include="Code\Bots\Mouse.cs" />
|
||||
<Compile Include="Code\Bots\Screenshoter.cs" />
|
||||
<Compile Include="Code\Bots\TetrisBot.cs" />
|
||||
<Compile Include="Code\Configuration\FileBackedConfiguration.cs" />
|
||||
<Compile Include="Code\Configuration\IConfiguration.cs" />
|
||||
|
||||
Reference in New Issue
Block a user