Image effects can be enabled/disabled using checkbox without requiring to remove effect, Added round corners effect

This commit is contained in:
Jaex 2014-10-19 17:02:09 +03:00
parent 56a3068ec9
commit 3a2da6a4a8
8 changed files with 111 additions and 3 deletions

View file

@ -291,6 +291,30 @@ public static Image AddCanvas(Image img, Padding margin)
return bmp;
}
public static Image RoundCorners(Image img, int cornerRadius)
{
Bitmap bmp = img.CreateEmptyBitmap();
using (Graphics g = Graphics.FromImage(bmp))
using (img)
{
g.SmoothingMode = SmoothingMode.AntiAlias;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
using (GraphicsPath gp = new GraphicsPath())
{
gp.AddRoundedRectangle(new RectangleF(0, 0, img.Width, img.Height), cornerRadius);
using (TextureBrush brush = new TextureBrush(img))
{
g.FillPath(brush, gp);
}
}
}
return bmp;
}
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);

View file

@ -23,12 +23,21 @@
#endregion License Information (GPL v3)
using System.ComponentModel;
using System.Drawing;
namespace ImageEffectsLib
{
public abstract class ImageEffect
{
[DefaultValue(true), Browsable(false)]
public bool Enabled { get; set; }
protected ImageEffect()
{
Enabled = true;
}
public abstract Image Apply(Image img);
}
}

View file

@ -38,7 +38,7 @@ public static Image ApplyEffects(Image img, List<ImageEffect> imageEffects)
if (imageEffects != null && imageEffects.Count > 0)
{
result = imageEffects.Aggregate(result, (current, imageEffect) => imageEffect.Apply(current));
result = imageEffects.Where(x => x.Enabled).Aggregate(result, (current, imageEffect) => imageEffect.Apply(current));
}
return result;

View file

@ -75,6 +75,7 @@ private void InitializeComponent()
//
// lvEffects
//
this.lvEffects.CheckBoxes = true;
this.lvEffects.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.chEffect});
this.lvEffects.FullRowSelect = true;
@ -85,6 +86,7 @@ private void InitializeComponent()
this.lvEffects.Name = "lvEffects";
this.lvEffects.UseCompatibleStateImageBehavior = false;
this.lvEffects.View = System.Windows.Forms.View.Details;
this.lvEffects.ItemChecked += new System.Windows.Forms.ItemCheckedEventHandler(this.lvEffects_ItemChecked);
this.lvEffects.SelectedIndexChanged += new System.EventHandler(this.lvEffects_SelectedIndexChanged);
this.lvEffects.KeyDown += new System.Windows.Forms.KeyEventHandler(this.lvEffects_KeyDown);
//

View file

@ -78,6 +78,7 @@ private void AddAllEffectsToTreeView()
typeof(Flip),
typeof(Resize),
typeof(Rotate),
typeof(RoundCorners),
typeof(Scale),
typeof(Skew));
@ -189,6 +190,7 @@ private void ClearEffects()
private void AddEffect(ImageEffect imageEffect)
{
ListViewItem lvi = new ListViewItem(imageEffect.GetType().GetDescription());
lvi.Checked = imageEffect.Enabled;
lvi.Tag = imageEffect;
if (lvEffects.SelectedIndices.Count > 0)
@ -297,6 +299,16 @@ private void lvEffects_SelectedIndexChanged(object sender, EventArgs e)
}
}
private void lvEffects_ItemChecked(object sender, ItemCheckedEventArgs e)
{
if (e.Item != null && e.Item.Tag is ImageEffect)
{
ImageEffect imageEffect = (ImageEffect)e.Item.Tag;
imageEffect.Enabled = e.Item.Checked;
UpdatePreview();
}
}
private void lvEffects_KeyDown(object sender, KeyEventArgs e)
{
switch (e.KeyData)

View file

@ -332,7 +332,7 @@
</data>
<data name="btnMoveUp.Text" xml:space="preserve">
<value>↑</value>
<comment>@Invariant</comment></data>
</data>
<data name="&gt;&gt;btnMoveUp.Name" xml:space="preserve">
<value>btnMoveUp</value>
</data>
@ -359,7 +359,7 @@
</data>
<data name="btnMoveDown.Text" xml:space="preserve">
<value>↓</value>
<comment>@Invariant</comment></data>
</data>
<data name="&gt;&gt;btnMoveDown.Name" xml:space="preserve">
<value>btnMoveDown</value>
</data>

View file

@ -93,6 +93,7 @@
<Compile Include="Adjustments\Inverse.cs" />
<Compile Include="Adjustments\Saturation.cs" />
<Compile Include="Manipulations\Crop.cs" />
<Compile Include="Manipulations\RoundCorners.cs" />
<Compile Include="Manipulations\Skew.cs" />
<Compile Include="Filters\Blur.cs" />
<Compile Include="Filters\Shadow.cs" />

View file

@ -0,0 +1,60 @@
#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;
namespace ImageEffectsLib
{
[Description("Round corners")]
internal class RoundCorners : ImageEffect
{
private int cornerRadius;
[DefaultValue(20)]
public int CornerRadius
{
get
{
return cornerRadius;
}
set
{
cornerRadius = value.Min(0);
}
}
public RoundCorners()
{
this.ApplyDefaultPropertyValues();
}
public override Image Apply(Image img)
{
return ImageHelpers.RoundCorners(img, CornerRadius);
}
}
}