Apply drawings to all capture methods inside region capture

This commit is contained in:
Jaex 2016-05-08 21:32:53 +03:00
parent a1175b13b6
commit 7eaac502c7
3 changed files with 84 additions and 72 deletions

View file

@ -694,31 +694,26 @@ public void UpdateRegionPath()
} }
} }
public override Image GetResultImage() protected override Image GetOutputImage()
{
if (SurfaceImage != null)
{ {
Image img = base.GetOutputImage();
if (AreaManager.DrawingShapes.Length > 0) if (AreaManager.DrawingShapes.Length > 0)
{ {
using (Bitmap bmp = new Bitmap(SurfaceImage)) using (Bitmap bmpCopy = new Bitmap(img))
using (Graphics g = Graphics.FromImage(bmp)) using (Graphics g = Graphics.FromImage(img))
{ {
foreach (BaseDrawingShape shape in AreaManager.DrawingShapes) foreach (BaseDrawingShape shape in AreaManager.DrawingShapes)
{ {
if (shape != null) if (shape != null)
{ {
shape.DrawOutput(g, bmp); shape.DrawOutput(g, bmpCopy);
}
}
} }
} }
return ShapeCaptureHelpers.GetRegionImage(bmp, regionFillPath, regionDrawPath, Config); return img;
}
}
return ShapeCaptureHelpers.GetRegionImage(SurfaceImage, regionFillPath, regionDrawPath, Config);
}
return null;
} }
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)

View file

@ -139,7 +139,7 @@ public virtual void Prepare()
using (Bitmap darkBackground = (Bitmap)SurfaceImage.Clone()) using (Bitmap darkBackground = (Bitmap)SurfaceImage.Clone())
using (Graphics g = Graphics.FromImage(darkBackground)) using (Graphics g = Graphics.FromImage(darkBackground))
{ {
using (Brush brush = new SolidBrush(Color.FromArgb(50, Color.Black))) using (Brush brush = new SolidBrush(Color.FromArgb(40, Color.Black)))
{ {
g.FillRectangle(brush, 0, 0, darkBackground.Width, darkBackground.Height); g.FillRectangle(brush, 0, 0, darkBackground.Width, darkBackground.Height);
} }
@ -260,7 +260,48 @@ protected override void OnPaint(PaintEventArgs e)
public virtual Image GetResultImage() public virtual Image GetResultImage()
{ {
return ShapeCaptureHelpers.GetRegionImage(SurfaceImage, regionFillPath, regionDrawPath, Config); if (Result == SurfaceResult.Region)
{
using (Image img = GetOutputImage())
{
return ShapeCaptureHelpers.GetRegionImage(img, regionFillPath, regionDrawPath, Config);
}
}
else if (Result == SurfaceResult.Fullscreen)
{
return GetOutputImage();
}
else if (Result == SurfaceResult.Monitor)
{
Screen[] screens = Screen.AllScreens;
if (MonitorIndex < screens.Length)
{
Screen screen = screens[MonitorIndex];
Rectangle screenRect = CaptureHelpers.ScreenToClient(screen.Bounds);
using (Image img = GetOutputImage())
{
return ImageHelpers.CropImage(img, screenRect);
}
}
}
else if (Result == SurfaceResult.ActiveMonitor)
{
Rectangle activeScreenRect = CaptureHelpers.GetActiveScreenBounds0Based();
using (Image img = GetOutputImage())
{
return ImageHelpers.CropImage(img, activeScreenRect);
}
}
return null;
}
protected virtual Image GetOutputImage()
{
return (Image)SurfaceImage.Clone();
} }
public virtual WindowInfo GetWindowInfo() public virtual WindowInfo GetWindowInfo()

View file

@ -2091,22 +2091,22 @@ private void CaptureRegion(CaptureType captureType, TaskSettings taskSettings, b
DoCapture(() => DoCapture(() =>
{ {
Image img = null; Image img = null;
Image screenshot = Screenshot.CaptureFullscreen(); Image screenshot = null;
try try
{ {
screenshot = Screenshot.CaptureFullscreen();
surface.Config = taskSettings.CaptureSettingsReference.SurfaceOptions; surface.Config = taskSettings.CaptureSettingsReference.SurfaceOptions;
surface.SurfaceImage = screenshot; surface.SurfaceImage = screenshot;
surface.Prepare(); surface.Prepare();
surface.ShowDialog(); surface.ShowDialog();
if (surface.Result == SurfaceResult.Region)
{
using (screenshot)
{
img = surface.GetResultImage(); img = surface.GetResultImage();
if (taskSettings.UploadSettings.RegionCaptureUseWindowPattern) if (img != null)
{
if (surface.Result == SurfaceResult.Region && taskSettings.UploadSettings.RegionCaptureUseWindowPattern)
{ {
WindowInfo windowInfo = surface.GetWindowInfo(); WindowInfo windowInfo = surface.GetWindowInfo();
@ -2119,47 +2119,23 @@ private void CaptureRegion(CaptureType captureType, TaskSettings taskSettings, b
}; };
} }
} }
}
}
else if (surface.Result == SurfaceResult.Fullscreen)
{
img = screenshot;
}
else if (surface.Result == SurfaceResult.Monitor)
{
Screen[] screens = Screen.AllScreens;
if (surface.MonitorIndex < screens.Length)
{
Screen screen = screens[surface.MonitorIndex];
Rectangle screenRect = CaptureHelpers.ScreenToClient(screen.Bounds);
using (screenshot)
{
img = ImageHelpers.CropImage(screenshot, screenRect);
}
}
}
else if (surface.Result == SurfaceResult.ActiveMonitor)
{
Rectangle activeScreenRect = CaptureHelpers.GetActiveScreenBounds0Based();
using (screenshot)
{
img = ImageHelpers.CropImage(screenshot, activeScreenRect);
}
}
if (img != null)
{
lastRegionCaptureType = LastRegionCaptureType.Surface; lastRegionCaptureType = LastRegionCaptureType.Surface;
} }
} }
finally finally
{
if (surface != null)
{ {
surface.Dispose(); surface.Dispose();
} }
if (screenshot != null)
{
screenshot.Dispose();
}
}
return img; return img;
}, captureType, taskSettings, autoHideForm); }, captureType, taskSettings, autoHideForm);
} }