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)
{
using (Bitmap bmp = new Bitmap(SurfaceImage))
using (Graphics g = Graphics.FromImage(bmp))
{
foreach (BaseDrawingShape shape in AreaManager.DrawingShapes)
{
if (shape != null)
{
shape.DrawOutput(g, bmp);
}
}
return ShapeCaptureHelpers.GetRegionImage(bmp, regionFillPath, regionDrawPath, Config); if (AreaManager.DrawingShapes.Length > 0)
{
using (Bitmap bmpCopy = new Bitmap(img))
using (Graphics g = Graphics.FromImage(img))
{
foreach (BaseDrawingShape shape in AreaManager.DrawingShapes)
{
if (shape != null)
{
shape.DrawOutput(g, bmpCopy);
}
} }
} }
return ShapeCaptureHelpers.GetRegionImage(SurfaceImage, regionFillPath, regionDrawPath, Config);
} }
return null; return img;
} }
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,73 +2091,49 @@ 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) img = surface.GetResultImage();
{
using (screenshot)
{
img = surface.GetResultImage();
if (taskSettings.UploadSettings.RegionCaptureUseWindowPattern)
{
WindowInfo windowInfo = surface.GetWindowInfo();
if (windowInfo != null)
{
img.Tag = new ImageTag
{
WindowTitle = windowInfo.Text,
ProcessName = windowInfo.ProcessName
};
}
}
}
}
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) if (img != null)
{ {
if (surface.Result == SurfaceResult.Region && taskSettings.UploadSettings.RegionCaptureUseWindowPattern)
{
WindowInfo windowInfo = surface.GetWindowInfo();
if (windowInfo != null)
{
img.Tag = new ImageTag
{
WindowTitle = windowInfo.Text,
ProcessName = windowInfo.ProcessName
};
}
}
lastRegionCaptureType = LastRegionCaptureType.Surface; lastRegionCaptureType = LastRegionCaptureType.Surface;
} }
} }
finally finally
{ {
surface.Dispose(); if (surface != null)
{
surface.Dispose();
}
if (screenshot != null)
{
screenshot.Dispose();
}
} }
return img; return img;