When rectangle capture is open if you press 1, 2, 3 ... 0 then it will capture monitor with that index (0 means 10. monitor)

This commit is contained in:
Jaex 2015-05-06 00:33:19 +03:00
parent bc6c17010c
commit 1e6df97a85
4 changed files with 43 additions and 7 deletions

View file

@ -206,8 +206,7 @@ public static Image ResizeImageLimit(Image img, int maxPixels)
public static Image CropImage(Image img, Rectangle rect)
{
if (img != null && rect.X >= 0 && rect.Y >= 0 && rect.Width > 0 && rect.Height > 0 &&
new Rectangle(0, 0, img.Width, img.Height).Contains(rect))
if (img != null && rect.X >= 0 && rect.Y >= 0 && rect.Width > 0 && rect.Height > 0 && new Rectangle(0, 0, img.Width, img.Height).Contains(rect))
{
using (Bitmap bmp = new Bitmap(img))
{
@ -220,8 +219,7 @@ public static Image CropImage(Image img, Rectangle rect)
public static Bitmap CropBitmap(Bitmap bmp, Rectangle rect)
{
if (bmp != null && rect.X >= 0 && rect.Y >= 0 && rect.Width > 0 && rect.Height > 0 &&
new Rectangle(0, 0, bmp.Width, bmp.Height).Contains(rect))
if (bmp != null && rect.X >= 0 && rect.Y >= 0 && rect.Width > 0 && rect.Height > 0 && new Rectangle(0, 0, bmp.Width, bmp.Height).Contains(rect))
{
return bmp.Clone(rect, bmp.PixelFormat);
}

View file

@ -40,7 +40,8 @@ public enum SurfaceResult
None,
Close,
Region,
Fullscreen
Fullscreen,
Monitor
}
internal enum NodePosition

View file

@ -45,6 +45,7 @@ public class Surface : Form
public Rectangle ScreenRectangle { get; private set; }
public Rectangle ScreenRectangle0Based { get; private set; }
public SurfaceResult Result { get; private set; }
public int MonitorIndex { get; private set; }
protected List<DrawableObject> DrawableObjects { get; set; }
@ -132,6 +133,23 @@ private void Surface_Shown(object sender, EventArgs e)
private void Surface_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9)
{
int index = e.KeyCode - Keys.D0;
if (index == 0)
{
index = 10;
}
index--;
MonitorIndex = index;
Close(SurfaceResult.Monitor);
return;
}
switch (e.KeyCode)
{
case Keys.Escape:

View file

@ -1851,13 +1851,32 @@ private void CaptureRegion(CaptureType captureType, TaskSettings taskSettings, b
if (surface.Result == SurfaceResult.Region)
{
img = surface.GetRegionImage();
screenshot.Dispose();
using (screenshot)
{
img = surface.GetRegionImage();
}
}
else if (surface.Result == SurfaceResult.Fullscreen)
{
img = screenshot;
}
else if (surface.Result == SurfaceResult.Monitor)
{
int index = surface.MonitorIndex;
Screen[] screens = Screen.AllScreens;
if (index < screens.Length)
{
Screen screen = screens[index];
Rectangle screenRect = CaptureHelpers.ScreenToClient(screen.Bounds);
using (screenshot)
{
img = ImageHelpers.CropImage(screenshot, screenRect);
}
}
}
if (img != null)
{