Added auto crop image effect

This commit is contained in:
Jaex 2018-01-21 14:32:15 +03:00
parent 1f4bf6f1c0
commit f2f62e7ffd
5 changed files with 61 additions and 23 deletions

View file

@ -1782,10 +1782,6 @@ public static Rectangle FindAutoCropRectangle(Bitmap bmp, bool sameColorCrop = f
return crop;
}
/// <summary>
/// If crop rectangle and source image rectangle is same then null will be returned.
/// After auto crop, source image will be disposed.
/// </summary>
public static Bitmap AutoCropImage(Bitmap bmp, bool sameColorCrop = false)
{
Rectangle source = new Rectangle(0, 0, bmp.Width, bmp.Height);
@ -1802,7 +1798,7 @@ public static Bitmap AutoCropImage(Bitmap bmp, bool sameColorCrop = false)
}
}
return null;
return bmp;
}
public static RotateFlipType RotateImageByExifOrientationData(Image img, bool removeExifOrientationData = true)

View file

@ -82,6 +82,7 @@ private void AddAllEffectsToContextMenu()
typeof(DrawText));
AddEffectToContextMenu(Resources.ImageEffectsForm_AddAllEffectsToTreeView_Manipulations,
typeof(AutoCrop),
typeof(Canvas),
typeof(Crop),
typeof(Flip),

View file

@ -171,9 +171,6 @@
<data name="lvEffects.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
<value>Top, Bottom, Left</value>
</data>
<data name="chEffect.Width" type="System.Int32, mscorlib">
<value>164</value>
</data>
<data name="lvEffects.Location" type="System.Drawing.Point, System.Drawing">
<value>8, 72</value>
</data>
@ -195,6 +192,9 @@
<data name="&gt;&gt;lvEffects.ZOrder" xml:space="preserve">
<value>18</value>
</data>
<data name="chEffect.Width" type="System.Int32, mscorlib">
<value>164</value>
</data>
<data name="btnRemove.Location" type="System.Drawing.Point, System.Drawing">
<value>120, 40</value>
</data>
@ -369,18 +369,6 @@
<metadata name="cmsLoadImage.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>126, 17</value>
</metadata>
<data name="tsmiLoadImageFromFile.Size" type="System.Drawing.Size, System.Drawing">
<value>130, 22</value>
</data>
<data name="tsmiLoadImageFromFile.Text" xml:space="preserve">
<value>From file...</value>
</data>
<data name="tsmiLoadImageFromClipboard.Size" type="System.Drawing.Size, System.Drawing">
<value>130, 22</value>
</data>
<data name="tsmiLoadImageFromClipboard.Text" xml:space="preserve">
<value>From clipboard</value>
</data>
<data name="cmsLoadImage.Size" type="System.Drawing.Size, System.Drawing">
<value>131, 48</value>
</data>
@ -414,6 +402,18 @@
<data name="&gt;&gt;mbLoadImage.ZOrder" xml:space="preserve">
<value>9</value>
</data>
<data name="tsmiLoadImageFromFile.Size" type="System.Drawing.Size, System.Drawing">
<value>130, 22</value>
</data>
<data name="tsmiLoadImageFromFile.Text" xml:space="preserve">
<value>From file...</value>
</data>
<data name="tsmiLoadImageFromClipboard.Size" type="System.Drawing.Size, System.Drawing">
<value>130, 22</value>
</data>
<data name="tsmiLoadImageFromClipboard.Text" xml:space="preserve">
<value>From clipboard</value>
</data>
<data name="btnAddPreset.Location" type="System.Drawing.Point, System.Drawing">
<value>8, 8</value>
</data>
@ -463,7 +463,7 @@
<value>7</value>
</data>
<data name="cbPresets.Location" type="System.Drawing.Point, System.Drawing">
<value>296, 8</value>
<value>296, 9</value>
</data>
<data name="cbPresets.Size" type="System.Drawing.Size, System.Drawing">
<value>304, 21</value>
@ -487,7 +487,7 @@
<value>True</value>
</data>
<data name="lblPresetName.Location" type="System.Drawing.Point, System.Drawing">
<value>608, 12</value>
<value>608, 13</value>
</data>
<data name="lblPresetName.Size" type="System.Drawing.Size, System.Drawing">
<value>38, 13</value>
@ -514,7 +514,7 @@
<value>Top, Left, Right</value>
</data>
<data name="txtPresetName.Location" type="System.Drawing.Point, System.Drawing">
<value>672, 8</value>
<value>672, 9</value>
</data>
<data name="txtPresetName.Size" type="System.Drawing.Size, System.Drawing">
<value>288, 20</value>

View file

@ -0,0 +1,40 @@
#region License Information (GPL v3)
/*
ShareX - A program that allows you to take screenshots and share any file type
Copyright (c) 2007-2018 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.ComponentModel;
using System.Drawing;
namespace ShareX.ImageEffectsLib
{
[Description("Auto crop")]
internal class AutoCrop : ImageEffect
{
public override Image Apply(Image img)
{
return ImageHelpers.AutoCropImage((Bitmap)img);
}
}
}

View file

@ -128,6 +128,7 @@
<Compile Include="Adjustments\Inverse.cs" />
<Compile Include="Adjustments\Saturation.cs" />
<Compile Include="ImageEffectPreset.cs" />
<Compile Include="Manipulations\AutoCrop.cs" />
<Compile Include="Manipulations\Crop.cs" />
<Compile Include="Manipulations\RoundedCorners.cs" />
<Compile Include="Manipulations\Skew.cs" />