From 7cfc326f7949eac687fcbde7cbf5d488aed6aad2 Mon Sep 17 00:00:00 2001 From: Jaex Date: Fri, 6 May 2016 19:55:16 +0300 Subject: [PATCH] Added simple blur drawing shape which renders blur only in output --- ShareX.ScreenCaptureLib/Enums.cs | 4 +- .../Forms/RectangleRegionForm.cs | 3 +- .../RegionHelpers/AreaManager.cs | 3 + .../Shapes/Drawing/BaseDrawingShape.cs | 5 ++ .../Shapes/Drawing/BlurDrawingShape.cs | 68 +++++++++++++++++++ .../ShareX.ScreenCaptureLib.csproj | 1 + 6 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 ShareX.ScreenCaptureLib/Shapes/Drawing/BlurDrawingShape.cs diff --git a/ShareX.ScreenCaptureLib/Enums.cs b/ShareX.ScreenCaptureLib/Enums.cs index 7aaf95ea8..10f6f4eb9 100644 --- a/ShareX.ScreenCaptureLib/Enums.cs +++ b/ShareX.ScreenCaptureLib/Enums.cs @@ -162,7 +162,9 @@ public enum ShapeType [Description("Drawing: Line")] DrawingLine, [Description("Drawing: Arrow")] - DrawingArrow + DrawingArrow, + [Description("Drawing: Blur")] + DrawingBlur } public enum RegionAnnotateMode diff --git a/ShareX.ScreenCaptureLib/Forms/RectangleRegionForm.cs b/ShareX.ScreenCaptureLib/Forms/RectangleRegionForm.cs index e6de1f265..b54b3c3ef 100644 --- a/ShareX.ScreenCaptureLib/Forms/RectangleRegionForm.cs +++ b/ShareX.ScreenCaptureLib/Forms/RectangleRegionForm.cs @@ -682,13 +682,14 @@ public override Image GetResultImage() { if (SurfaceImage != null && AreaManager.DrawingShapes.Length > 0) { + using (Bitmap surfaceCopy = (Bitmap)SurfaceImage.Clone()) using (Graphics g = Graphics.FromImage(SurfaceImage)) { foreach (BaseDrawingShape shape in AreaManager.DrawingShapes) { if (shape != null) { - shape.Draw(g); + shape.DrawOutput(g, surfaceCopy); } } } diff --git a/ShareX.ScreenCaptureLib/RegionHelpers/AreaManager.cs b/ShareX.ScreenCaptureLib/RegionHelpers/AreaManager.cs index 3f2451a61..58278d827 100644 --- a/ShareX.ScreenCaptureLib/RegionHelpers/AreaManager.cs +++ b/ShareX.ScreenCaptureLib/RegionHelpers/AreaManager.cs @@ -693,6 +693,9 @@ public BaseShape CreateRegionShape(Rectangle rect) case ShapeType.DrawingArrow: shape = new ArrowDrawingShape(); break; + case ShapeType.DrawingBlur: + shape = new BlurDrawingShape(); + break; } shape.Rectangle = rect; diff --git a/ShareX.ScreenCaptureLib/Shapes/Drawing/BaseDrawingShape.cs b/ShareX.ScreenCaptureLib/Shapes/Drawing/BaseDrawingShape.cs index 488794c47..54bcfccaf 100644 --- a/ShareX.ScreenCaptureLib/Shapes/Drawing/BaseDrawingShape.cs +++ b/ShareX.ScreenCaptureLib/Shapes/Drawing/BaseDrawingShape.cs @@ -41,6 +41,11 @@ public abstract class BaseDrawingShape : BaseShape public abstract void Draw(Graphics g); + public virtual void DrawOutput(Graphics g, Bitmap bmp) + { + Draw(g); + } + public override void AddShapePath(GraphicsPath gp, Rectangle rect) { gp.AddRectangle(rect); diff --git a/ShareX.ScreenCaptureLib/Shapes/Drawing/BlurDrawingShape.cs b/ShareX.ScreenCaptureLib/Shapes/Drawing/BlurDrawingShape.cs new file mode 100644 index 000000000..1e6aa2a09 --- /dev/null +++ b/ShareX.ScreenCaptureLib/Shapes/Drawing/BlurDrawingShape.cs @@ -0,0 +1,68 @@ +#region License Information (GPL v3) + +/* + ShareX - A program that allows you to take screenshots and share any file type + Copyright (c) 2007-2016 ShareX Team + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Optionally you can also view the license at . +*/ + +#endregion License Information (GPL v3) + +using ShareX.HelpersLib; +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Drawing.Drawing2D; +using System.Linq; +using System.Text; +using System.Windows.Forms; + +namespace ShareX.ScreenCaptureLib +{ + public class BlurDrawingShape : BaseDrawingShape + { + public override ShapeType ShapeType { get; } = ShapeType.DrawingBlur; + + public override void Draw(Graphics g) + { + using (Brush brush = new SolidBrush(Color.FromArgb(200, Color.Black))) + { + g.FillRectangle(brush, Rectangle); + } + + if (Rectangle.Width > 10 && Rectangle.Height > 10) + { + using (Font font = new Font("Verdana", 15, FontStyle.Bold)) + using (StringFormat sf = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center }) + { + g.DrawString("Blur", font, Brushes.White, Rectangle, sf); + } + } + } + + public override void DrawOutput(Graphics g, Bitmap bmp) + { + using (Bitmap croppedImage = ImageHelpers.CropBitmap(bmp, Rectangle)) + { + ImageHelpers.Blur(croppedImage, 20); + + g.DrawImage(croppedImage, Rectangle); + } + } + } +} \ No newline at end of file diff --git a/ShareX.ScreenCaptureLib/ShareX.ScreenCaptureLib.csproj b/ShareX.ScreenCaptureLib/ShareX.ScreenCaptureLib.csproj index fd658a215..557cae27f 100644 --- a/ShareX.ScreenCaptureLib/ShareX.ScreenCaptureLib.csproj +++ b/ShareX.ScreenCaptureLib/ShareX.ScreenCaptureLib.csproj @@ -83,6 +83,7 @@ +