Smart eraser tool gonna use dimmed background color in region capture but output result gonna use proper color

This commit is contained in:
Jaex 2020-03-20 23:22:08 +03:00
parent 4a58f310ab
commit f49c345ffd
4 changed files with 50 additions and 17 deletions

View file

@ -71,6 +71,7 @@ public sealed class RegionCaptureForm : Form
internal ShapeManager ShapeManager { get; private set; }
internal bool IsClosing { get; private set; }
internal Bitmap DimmedCanvas;
internal Image CustomNodeImage = Resources.CircleNode;
internal int ToolbarHeight;
@ -324,13 +325,15 @@ internal void InitBackground(Bitmap canvas, bool centerCanvas = true)
}
else if (Options.UseDimming)
{
using (Bitmap darkBackground = (Bitmap)Canvas.Clone())
using (Graphics g = Graphics.FromImage(darkBackground))
DimmedCanvas?.Dispose();
DimmedCanvas = (Bitmap)Canvas.Clone();
using (Graphics g = Graphics.FromImage(DimmedCanvas))
using (Brush brush = new SolidBrush(Color.FromArgb(30, Color.Black)))
{
g.FillRectangle(brush, 0, 0, darkBackground.Width, darkBackground.Height);
g.FillRectangle(brush, 0, 0, DimmedCanvas.Width, DimmedCanvas.Height);
backgroundBrush = new TextureBrush(darkBackground) { WrapMode = WrapMode.Clamp };
backgroundBrush = new TextureBrush(DimmedCanvas) { WrapMode = WrapMode.Clamp };
}
backgroundHighlightBrush = new TextureBrush(Canvas) { WrapMode = WrapMode.Clamp };
@ -1450,6 +1453,7 @@ protected override void Dispose(bool disposing)
}
regionDrawPath?.Dispose();
DimmedCanvas?.Dispose();
Canvas?.Dispose();
base.Dispose(disposing);

View file

@ -111,7 +111,8 @@ public Bitmap CaptureActiveMonitor()
private Bitmap CaptureRectangleNative(Rectangle rect, bool captureCursor = false)
{
return CaptureRectangleNative(NativeMethods.GetDesktopWindow(), rect, captureCursor);
IntPtr handle = NativeMethods.GetDesktopWindow();
return CaptureRectangleNative(handle, rect, captureCursor);
}
private Bitmap CaptureRectangleNative(IntPtr handle, Rectangle rect, bool captureCursor = false)

View file

@ -31,23 +31,48 @@ public class SmartEraserDrawingShape : BaseDrawingShape
{
public override ShapeType ShapeType { get; } = ShapeType.DrawingSmartEraser;
private Color eraserColor;
private Color eraserDimmedColor;
public override void OnConfigLoad()
{
}
public override void OnConfigSave()
{
}
public override void OnCreating()
{
base.OnCreating();
Color color = Manager.GetCurrentColor();
eraserColor = Manager.GetCurrentColor();
if (color.IsEmpty)
if (eraserColor.IsEmpty)
{
color = Color.White;
eraserColor = Color.White;
}
FillColor = color;
if (Manager.Form.DimmedCanvas != null)
{
eraserDimmedColor = Manager.GetCurrentColor(Manager.Form.DimmedCanvas);
}
}
public override void OnDraw(Graphics g)
{
using (Brush brush = new SolidBrush(FillColor))
Color color;
if (!Manager.IsRenderingOutput && !eraserDimmedColor.IsEmpty)
{
color = eraserDimmedColor;
}
else
{
color = eraserColor;
}
using (Brush brush = new SolidBrush(color))
{
g.FillRectangle(brush, Rectangle);
}

View file

@ -1698,29 +1698,32 @@ public Bitmap CropImage(Rectangle rect, bool onlyIfSizeDifferent = false)
return null;
}
public Color GetColor(Point pos)
public Color GetColor(Bitmap bmp, Point pos)
{
Bitmap bmpCanvas = Form.Canvas as Bitmap;
if (bmpCanvas != null)
if (bmp != null)
{
Point position = CaptureHelpers.ScreenToClient(pos);
Point offset = CaptureHelpers.ScreenToClient(Form.CanvasRectangle.Location);
position.X -= offset.X;
position.Y -= offset.Y;
if (position.X.IsBetween(0, bmpCanvas.Width - 1) && position.Y.IsBetween(0, bmpCanvas.Height - 1))
if (position.X.IsBetween(0, bmp.Width - 1) && position.Y.IsBetween(0, bmp.Height - 1))
{
return bmpCanvas.GetPixel(position.X, position.Y);
return bmp.GetPixel(position.X, position.Y);
}
}
return Color.Empty;
}
public Color GetCurrentColor(Bitmap bmp)
{
return GetColor(bmp, InputManager.ClientMousePosition);
}
public Color GetCurrentColor()
{
return GetColor(InputManager.ClientMousePosition);
return GetCurrentColor(Form.Canvas);
}
public void NewImage()