From f2f62e7ffd4bc3ac718ed76beda1190b3c361b95 Mon Sep 17 00:00:00 2001 From: Jaex Date: Sun, 21 Jan 2018 14:32:15 +0300 Subject: [PATCH] Added auto crop image effect --- ShareX.HelpersLib/Helpers/ImageHelpers.cs | 6 +-- ShareX.ImageEffectsLib/ImageEffectsForm.cs | 1 + ShareX.ImageEffectsLib/ImageEffectsForm.resx | 36 ++++++++--------- .../Manipulations/AutoCrop.cs | 40 +++++++++++++++++++ .../ShareX.ImageEffectsLib.csproj | 1 + 5 files changed, 61 insertions(+), 23 deletions(-) create mode 100644 ShareX.ImageEffectsLib/Manipulations/AutoCrop.cs diff --git a/ShareX.HelpersLib/Helpers/ImageHelpers.cs b/ShareX.HelpersLib/Helpers/ImageHelpers.cs index 5853ff9f1..173407249 100644 --- a/ShareX.HelpersLib/Helpers/ImageHelpers.cs +++ b/ShareX.HelpersLib/Helpers/ImageHelpers.cs @@ -1782,10 +1782,6 @@ public static Rectangle FindAutoCropRectangle(Bitmap bmp, bool sameColorCrop = f return crop; } - /// - /// If crop rectangle and source image rectangle is same then null will be returned. - /// After auto crop, source image will be disposed. - /// 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) diff --git a/ShareX.ImageEffectsLib/ImageEffectsForm.cs b/ShareX.ImageEffectsLib/ImageEffectsForm.cs index 45cdb8125..dd1664434 100644 --- a/ShareX.ImageEffectsLib/ImageEffectsForm.cs +++ b/ShareX.ImageEffectsLib/ImageEffectsForm.cs @@ -82,6 +82,7 @@ private void AddAllEffectsToContextMenu() typeof(DrawText)); AddEffectToContextMenu(Resources.ImageEffectsForm_AddAllEffectsToTreeView_Manipulations, + typeof(AutoCrop), typeof(Canvas), typeof(Crop), typeof(Flip), diff --git a/ShareX.ImageEffectsLib/ImageEffectsForm.resx b/ShareX.ImageEffectsLib/ImageEffectsForm.resx index 18f143fcc..1212a3263 100644 --- a/ShareX.ImageEffectsLib/ImageEffectsForm.resx +++ b/ShareX.ImageEffectsLib/ImageEffectsForm.resx @@ -171,9 +171,6 @@ Top, Bottom, Left - - 164 - 8, 72 @@ -195,6 +192,9 @@ 18 + + 164 + 120, 40 @@ -369,18 +369,6 @@ 126, 17 - - 130, 22 - - - From file... - - - 130, 22 - - - From clipboard - 131, 48 @@ -414,6 +402,18 @@ 9 + + 130, 22 + + + From file... + + + 130, 22 + + + From clipboard + 8, 8 @@ -463,7 +463,7 @@ 7 - 296, 8 + 296, 9 304, 21 @@ -487,7 +487,7 @@ True - 608, 12 + 608, 13 38, 13 @@ -514,7 +514,7 @@ Top, Left, Right - 672, 8 + 672, 9 288, 20 diff --git a/ShareX.ImageEffectsLib/Manipulations/AutoCrop.cs b/ShareX.ImageEffectsLib/Manipulations/AutoCrop.cs new file mode 100644 index 000000000..1105cb3e4 --- /dev/null +++ b/ShareX.ImageEffectsLib/Manipulations/AutoCrop.cs @@ -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 . +*/ + +#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); + } + } +} \ No newline at end of file diff --git a/ShareX.ImageEffectsLib/ShareX.ImageEffectsLib.csproj b/ShareX.ImageEffectsLib/ShareX.ImageEffectsLib.csproj index a9f3ebce7..e391824c0 100644 --- a/ShareX.ImageEffectsLib/ShareX.ImageEffectsLib.csproj +++ b/ShareX.ImageEffectsLib/ShareX.ImageEffectsLib.csproj @@ -128,6 +128,7 @@ +