mirror of
https://github.com/ShareX/ShareX.git
synced 2024-09-30 01:07:21 +13:00
Image effects can be enabled/disabled using checkbox without requiring to remove effect, Added round corners effect
This commit is contained in:
parent
56a3068ec9
commit
3a2da6a4a8
8 changed files with 111 additions and 3 deletions
|
@ -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);
|
||||
|
|
|
@ -23,12 +23,21 @@ You should have received a copy of the GNU General Public License
|
|||
|
||||
#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);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
2
ImageEffectsLib/ImageEffectsForm.Designer.cs
generated
2
ImageEffectsLib/ImageEffectsForm.Designer.cs
generated
|
@ -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);
|
||||
//
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -332,7 +332,7 @@
|
|||
</data>
|
||||
<data name="btnMoveUp.Text" xml:space="preserve">
|
||||
<value>↑</value>
|
||||
<comment>@Invariant</comment></data>
|
||||
</data>
|
||||
<data name=">>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=">>btnMoveDown.Name" xml:space="preserve">
|
||||
<value>btnMoveDown</value>
|
||||
</data>
|
||||
|
|
|
@ -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" />
|
||||
|
|
60
ImageEffectsLib/Manipulations/RoundCorners.cs
Normal file
60
ImageEffectsLib/Manipulations/RoundCorners.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue