mirror of
https://github.com/ShareX/ShareX.git
synced 2024-09-29 17:02:05 +13:00
Recognize window info for custom region and active monitor capture too
This commit is contained in:
parent
42d61347cd
commit
c2036f2bed
5 changed files with 41 additions and 31 deletions
|
@ -23,6 +23,7 @@ You should have received a copy of the GNU General Public License
|
|||
|
||||
#endregion License Information (GPL v3)
|
||||
|
||||
using ShareX.HelpersLib;
|
||||
using System.Drawing;
|
||||
|
||||
namespace ShareX
|
||||
|
@ -31,8 +32,10 @@ public class CaptureActiveMonitor : CaptureBase
|
|||
{
|
||||
protected override ImageInfo Execute(TaskSettings taskSettings)
|
||||
{
|
||||
Image img = TaskHelpers.GetScreenshot(taskSettings).CaptureActiveMonitor();
|
||||
return new ImageInfo(img);
|
||||
Rectangle rect = CaptureHelpers.GetActiveScreenWorkingArea();
|
||||
ImageInfo imageInfo = CreateImageInfo(rect);
|
||||
imageInfo.Image = TaskHelpers.GetScreenshot(taskSettings).CaptureActiveMonitor();
|
||||
return imageInfo;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -23,19 +23,13 @@ You should have received a copy of the GNU General Public License
|
|||
|
||||
#endregion License Information (GPL v3)
|
||||
|
||||
using ShareX.HelpersLib;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
|
||||
namespace ShareX
|
||||
{
|
||||
public class CaptureActiveWindow : CaptureBase
|
||||
{
|
||||
protected override ImageInfo Execute(TaskSettings taskSettings)
|
||||
{
|
||||
ImageInfo imageInfo = new ImageInfo();
|
||||
imageInfo.WindowTitle = NativeMethods.GetForegroundWindowText();
|
||||
imageInfo.ProcessName = NativeMethods.GetForegroundWindowProcessName();
|
||||
ImageInfo imageInfo = CreateImageInfo();
|
||||
|
||||
if (taskSettings.CaptureSettings.CaptureTransparent && !taskSettings.CaptureSettings.CaptureClientArea)
|
||||
{
|
||||
|
|
|
@ -24,7 +24,9 @@ You should have received a copy of the GNU General Public License
|
|||
#endregion License Information (GPL v3)
|
||||
|
||||
using ShareX.HelpersLib;
|
||||
using ShareX.ScreenCaptureLib;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Threading;
|
||||
|
||||
namespace ShareX
|
||||
|
@ -112,5 +114,32 @@ private void AfterCapture(ImageInfo imageInfo, TaskSettings taskSettings)
|
|||
UploadManager.RunImageTask(imageInfo, taskSettings);
|
||||
}
|
||||
}
|
||||
|
||||
protected ImageInfo CreateImageInfo()
|
||||
{
|
||||
return CreateImageInfo(Rectangle.Empty, null);
|
||||
}
|
||||
|
||||
protected ImageInfo CreateImageInfo(Rectangle insideRect)
|
||||
{
|
||||
return CreateImageInfo(insideRect, "explorer");
|
||||
}
|
||||
|
||||
protected ImageInfo CreateImageInfo(Rectangle insideRect, string ignoreProcess)
|
||||
{
|
||||
ImageInfo imageInfo = new ImageInfo();
|
||||
|
||||
IntPtr handle = NativeMethods.GetForegroundWindow();
|
||||
WindowInfo windowInfo = new WindowInfo(handle);
|
||||
|
||||
if ((ignoreProcess == null || !windowInfo.ProcessName.Equals(ignoreProcess, StringComparison.InvariantCultureIgnoreCase)) &&
|
||||
(insideRect.IsEmpty || windowInfo.Rectangle.Contains(insideRect)))
|
||||
{
|
||||
imageInfo.WindowTitle = windowInfo.Text;
|
||||
imageInfo.ProcessName = windowInfo.ProcessName;
|
||||
}
|
||||
|
||||
return imageInfo;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -31,9 +31,10 @@ public class CaptureCustomRegion : CaptureBase
|
|||
{
|
||||
protected override ImageInfo Execute(TaskSettings taskSettings)
|
||||
{
|
||||
Rectangle regionBounds = taskSettings.CaptureSettings.CaptureCustomRegion;
|
||||
Image img = TaskHelpers.GetScreenshot(taskSettings).CaptureRectangle(regionBounds);
|
||||
return new ImageInfo(img);
|
||||
Rectangle rect = taskSettings.CaptureSettings.CaptureCustomRegion;
|
||||
ImageInfo imageInfo = CreateImageInfo(rect);
|
||||
imageInfo.Image = TaskHelpers.GetScreenshot(taskSettings).CaptureRectangle(rect);
|
||||
return imageInfo;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -24,8 +24,6 @@ You should have received a copy of the GNU General Public License
|
|||
#endregion License Information (GPL v3)
|
||||
|
||||
using ShareX.HelpersLib;
|
||||
using ShareX.ScreenCaptureLib;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
|
||||
namespace ShareX
|
||||
|
@ -34,24 +32,9 @@ public class CaptureFullscreen : CaptureBase
|
|||
{
|
||||
protected override ImageInfo Execute(TaskSettings taskSettings)
|
||||
{
|
||||
ImageInfo imageInfo = new ImageInfo();
|
||||
|
||||
IntPtr handle = NativeMethods.GetForegroundWindow();
|
||||
WindowInfo windowInfo = new WindowInfo(handle);
|
||||
|
||||
if (!windowInfo.ProcessName.Equals("explorer", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
Rectangle screenRect = CaptureHelpers.GetScreenWorkingArea();
|
||||
|
||||
if (windowInfo.Rectangle.Contains(screenRect))
|
||||
{
|
||||
imageInfo.WindowTitle = windowInfo.Text;
|
||||
imageInfo.ProcessName = windowInfo.ProcessName;
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle rect = CaptureHelpers.GetScreenWorkingArea();
|
||||
ImageInfo imageInfo = CreateImageInfo(rect);
|
||||
imageInfo.Image = TaskHelpers.GetScreenshot(taskSettings).CaptureFullscreen();
|
||||
|
||||
return imageInfo;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue