Added simple blur drawing shape which renders blur only in output

This commit is contained in:
Jaex 2016-05-06 19:55:16 +03:00
parent 133b5c3fe9
commit 7cfc326f79
6 changed files with 82 additions and 2 deletions

View file

@ -162,7 +162,9 @@ public enum ShapeType
[Description("Drawing: Line")]
DrawingLine,
[Description("Drawing: Arrow")]
DrawingArrow
DrawingArrow,
[Description("Drawing: Blur")]
DrawingBlur
}
public enum RegionAnnotateMode

View file

@ -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);
}
}
}

View file

@ -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;

View file

@ -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);

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
#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);
}
}
}
}

View file

@ -83,6 +83,7 @@
<Compile Include="Shapes\BaseShape.cs" />
<Compile Include="Shapes\Drawing\ArrowDrawingShape.cs" />
<Compile Include="Shapes\Drawing\BaseDrawingShape.cs" />
<Compile Include="Shapes\Drawing\BlurDrawingShape.cs" />
<Compile Include="Shapes\Drawing\EllipseDrawingShape.cs" />
<Compile Include="Shapes\Drawing\LineDrawingShape.cs" />
<Compile Include="Shapes\Drawing\RectangleDrawingShape.cs" />