Added Outline image effect

This commit is contained in:
Jaex 2014-10-20 22:37:51 +03:00
parent a6aaca8743
commit 3f13e0f025
5 changed files with 97 additions and 1 deletions

View file

@ -315,6 +315,37 @@ public static Image RoundedCorners(Image img, int cornerRadius)
return bmp; return bmp;
} }
public static Image Outline(Image img, int borderSize, Color borderColor)
{
Bitmap result = img.CreateEmptyBitmap(borderSize * 2, borderSize * 2);
ColorMatrix maskMatrix = new ColorMatrix();
maskMatrix.Matrix00 = 0;
maskMatrix.Matrix11 = 0;
maskMatrix.Matrix22 = 0;
maskMatrix.Matrix33 = 1;
maskMatrix.Matrix40 = ((float)borderColor.R).Remap(0, 255, 0, 1);
maskMatrix.Matrix41 = ((float)borderColor.G).Remap(0, 255, 0, 1);
maskMatrix.Matrix42 = ((float)borderColor.B).Remap(0, 255, 0, 1);
using (img)
using (Image shadow = maskMatrix.Apply(img))
using (Graphics g = Graphics.FromImage(result))
{
for (int i = 0; i <= borderSize * 2; i++)
{
g.DrawImage(shadow, new Rectangle(i, 0, shadow.Width, shadow.Height));
g.DrawImage(shadow, new Rectangle(i, borderSize * 2, shadow.Width, shadow.Height));
g.DrawImage(shadow, new Rectangle(0, i, shadow.Width, shadow.Height));
g.DrawImage(shadow, new Rectangle(borderSize * 2, i, shadow.Width, shadow.Height));
}
g.DrawImage(img, new Rectangle(borderSize, borderSize, img.Width, img.Height));
}
return result;
}
public static Image DrawReflection(Image img, int percentage, int maxAlpha, int minAlpha, int offset, bool skew, int skewSize) public static Image DrawReflection(Image img, int percentage, int maxAlpha, int minAlpha, int offset, bool skew, int skewSize)
{ {
Bitmap reflection = AddReflection(img, percentage, maxAlpha, minAlpha); Bitmap reflection = AddReflection(img, percentage, maxAlpha, minAlpha);

View file

@ -0,0 +1,63 @@
#region License Information (GPL v3)
/*
ShareX - A program that allows you to take screenshots and share any file type
Copyright (C) 2007-2014 ShareX Developers
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 HelpersLib;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
namespace ImageEffectsLib
{
internal class Outline : ImageEffect
{
private int size;
[DefaultValue(1)]
public int Size
{
get
{
return size;
}
set
{
size = value.Min(1);
}
}
[DefaultValue(typeof(Color), "Black"), Editor(typeof(MyColorEditor), typeof(UITypeEditor)), TypeConverter(typeof(MyColorConverter))]
public Color Color { get; set; }
public Outline()
{
this.ApplyDefaultPropertyValues();
}
public override Image Apply(Image img)
{
return ImageHelpers.Outline(img, Size, Color);
}
}
}

View file

@ -104,6 +104,7 @@ private void AddAllEffectsToTreeView()
typeof(GaussianBlur), typeof(GaussianBlur),
typeof(MatrixConvolution), typeof(MatrixConvolution),
typeof(MeanRemoval), typeof(MeanRemoval),
typeof(Outline),
typeof(Pixelate), typeof(Pixelate),
typeof(Reflection), typeof(Reflection),
typeof(Shadow), typeof(Shadow),

View file

@ -80,6 +80,7 @@
<Compile Include="Filters\GaussianBlur.cs" /> <Compile Include="Filters\GaussianBlur.cs" />
<Compile Include="Filters\MatrixConvolution.cs" /> <Compile Include="Filters\MatrixConvolution.cs" />
<Compile Include="Filters\MeanRemoval.cs" /> <Compile Include="Filters\MeanRemoval.cs" />
<Compile Include="Filters\Outline.cs" />
<Compile Include="Filters\Pixelate.cs" /> <Compile Include="Filters\Pixelate.cs" />
<Compile Include="Filters\Sharpen.cs" /> <Compile Include="Filters\Sharpen.cs" />
<Compile Include="Filters\Smooth.cs" /> <Compile Include="Filters\Smooth.cs" />

View file

@ -420,4 +420,4 @@ protected virtual void AddShapePath(GraphicsPath graphicsPath, Rectangle rect)
graphicsPath.AddRectangle(rect); graphicsPath.AddRectangle(rect);
} }
} }
} }