mirror of
https://github.com/ShareX/ShareX.git
synced 2024-09-30 01:07:21 +13:00
Added "Padding" option to "Auto crop" image effect
This commit is contained in:
parent
911c81b065
commit
1591951c08
2 changed files with 23 additions and 4 deletions
|
@ -452,6 +452,11 @@ public static Bitmap AddCanvas(Image img, int margin)
|
||||||
return AddCanvas(img, new Padding(margin));
|
return AddCanvas(img, new Padding(margin));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Bitmap AddCanvas(Image img, int margin, Color canvasColor)
|
||||||
|
{
|
||||||
|
return AddCanvas(img, new Padding(margin), canvasColor);
|
||||||
|
}
|
||||||
|
|
||||||
public static Bitmap AddCanvas(Image img, Padding margin)
|
public static Bitmap AddCanvas(Image img, Padding margin)
|
||||||
{
|
{
|
||||||
return AddCanvas(img, margin, Color.Transparent);
|
return AddCanvas(img, margin, Color.Transparent);
|
||||||
|
@ -2464,7 +2469,7 @@ public static Rectangle FindAutoCropRectangle(Bitmap bmp, bool sameColorCrop = f
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Bitmap AutoCropImage(Bitmap bmp, bool sameColorCrop = false,
|
public static Bitmap AutoCropImage(Bitmap bmp, bool sameColorCrop = false,
|
||||||
AnchorStyles sides = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right)
|
AnchorStyles sides = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right, int padding = 0)
|
||||||
{
|
{
|
||||||
Rectangle source = new Rectangle(0, 0, bmp.Width, bmp.Height);
|
Rectangle source = new Rectangle(0, 0, bmp.Width, bmp.Height);
|
||||||
Rectangle rect = FindAutoCropRectangle(bmp, sameColorCrop, sides);
|
Rectangle rect = FindAutoCropRectangle(bmp, sameColorCrop, sides);
|
||||||
|
@ -2475,10 +2480,21 @@ public static Bitmap AutoCropImage(Bitmap bmp, bool sameColorCrop = false,
|
||||||
|
|
||||||
if (croppedBitmap != null)
|
if (croppedBitmap != null)
|
||||||
{
|
{
|
||||||
bmp.Dispose();
|
using (bmp)
|
||||||
|
{
|
||||||
|
if (padding > 0)
|
||||||
|
{
|
||||||
|
using (croppedBitmap)
|
||||||
|
{
|
||||||
|
Color color = bmp.GetPixel(0, 0);
|
||||||
|
return AddCanvas(croppedBitmap, padding, color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return croppedBitmap;
|
return croppedBitmap;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return bmp;
|
return bmp;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,9 @@ internal class AutoCrop : ImageEffect
|
||||||
[DefaultValue(AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right)]
|
[DefaultValue(AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right)]
|
||||||
public AnchorStyles Sides { get; set; }
|
public AnchorStyles Sides { get; set; }
|
||||||
|
|
||||||
|
[DefaultValue(0)]
|
||||||
|
public int Padding { get; set; }
|
||||||
|
|
||||||
public AutoCrop()
|
public AutoCrop()
|
||||||
{
|
{
|
||||||
this.ApplyDefaultPropertyValues();
|
this.ApplyDefaultPropertyValues();
|
||||||
|
@ -43,7 +46,7 @@ public AutoCrop()
|
||||||
|
|
||||||
public override Bitmap Apply(Bitmap bmp)
|
public override Bitmap Apply(Bitmap bmp)
|
||||||
{
|
{
|
||||||
return ImageHelpers.AutoCropImage(bmp, false, Sides);
|
return ImageHelpers.AutoCropImage(bmp, true, Sides, Padding);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue