mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-01 17:56:51 +13:00
Added Outline image effect
This commit is contained in:
parent
a6aaca8743
commit
3f13e0f025
5 changed files with 97 additions and 1 deletions
|
@ -315,6 +315,37 @@ public static Image RoundedCorners(Image img, int cornerRadius)
|
|||
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)
|
||||
{
|
||||
Bitmap reflection = AddReflection(img, percentage, maxAlpha, minAlpha);
|
||||
|
|
63
ImageEffectsLib/Filters/Outline.cs
Normal file
63
ImageEffectsLib/Filters/Outline.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -104,6 +104,7 @@ private void AddAllEffectsToTreeView()
|
|||
typeof(GaussianBlur),
|
||||
typeof(MatrixConvolution),
|
||||
typeof(MeanRemoval),
|
||||
typeof(Outline),
|
||||
typeof(Pixelate),
|
||||
typeof(Reflection),
|
||||
typeof(Shadow),
|
||||
|
|
|
@ -80,6 +80,7 @@
|
|||
<Compile Include="Filters\GaussianBlur.cs" />
|
||||
<Compile Include="Filters\MatrixConvolution.cs" />
|
||||
<Compile Include="Filters\MeanRemoval.cs" />
|
||||
<Compile Include="Filters\Outline.cs" />
|
||||
<Compile Include="Filters\Pixelate.cs" />
|
||||
<Compile Include="Filters\Sharpen.cs" />
|
||||
<Compile Include="Filters\Smooth.cs" />
|
||||
|
|
Loading…
Reference in a new issue