Added dash style option to "Border" image effect

This commit is contained in:
Jaex 2021-03-16 08:08:41 +03:00
parent 03bf950ba8
commit 6799edaa1b
2 changed files with 13 additions and 8 deletions

View file

@ -655,15 +655,16 @@ public static Bitmap AddReflection(Image img, int percentage, int maxAlpha, int
return reflection;
}
public static Bitmap DrawBorder(Bitmap bmp, Color borderColor, int borderSize, BorderType borderType)
public static Bitmap DrawBorder(Bitmap bmp, Color borderColor, int borderSize, BorderType borderType, DashStyle dashStyle = DashStyle.Solid)
{
using (Pen borderPen = new Pen(borderColor, borderSize) { Alignment = PenAlignment.Inset })
using (Pen borderPen = new Pen(borderColor, borderSize) { Alignment = PenAlignment.Inset, DashStyle = dashStyle })
{
return DrawBorder(bmp, borderPen, borderType);
}
}
public static Bitmap DrawBorder(Bitmap bmp, Color fromBorderColor, Color toBorderColor, LinearGradientMode gradientType, int borderSize, BorderType borderType)
public static Bitmap DrawBorder(Bitmap bmp, Color fromBorderColor, Color toBorderColor, LinearGradientMode gradientType, int borderSize, BorderType borderType,
DashStyle dashStyle = DashStyle.Solid)
{
int width = bmp.Width;
int height = bmp.Height;
@ -675,13 +676,13 @@ public static Bitmap DrawBorder(Bitmap bmp, Color fromBorderColor, Color toBorde
}
using (LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, width, height), fromBorderColor, toBorderColor, gradientType))
using (Pen borderPen = new Pen(brush, borderSize) { Alignment = PenAlignment.Inset })
using (Pen borderPen = new Pen(brush, borderSize) { Alignment = PenAlignment.Inset, DashStyle = dashStyle })
{
return DrawBorder(bmp, borderPen, borderType);
}
}
public static Bitmap DrawBorder(Bitmap bmp, GradientInfo gradientInfo, int borderSize, BorderType borderType)
public static Bitmap DrawBorder(Bitmap bmp, GradientInfo gradientInfo, int borderSize, BorderType borderType, DashStyle dashStyle = DashStyle.Solid)
{
int width = bmp.Width;
int height = bmp.Height;
@ -693,7 +694,7 @@ public static Bitmap DrawBorder(Bitmap bmp, GradientInfo gradientInfo, int borde
}
using (LinearGradientBrush brush = gradientInfo.GetGradientBrush(new Rectangle(0, 0, width, height)))
using (Pen borderPen = new Pen(brush, borderSize) { Alignment = PenAlignment.Inset })
using (Pen borderPen = new Pen(brush, borderSize) { Alignment = PenAlignment.Inset, DashStyle = dashStyle })
{
return DrawBorder(bmp, borderPen, borderType);
}

View file

@ -27,6 +27,7 @@
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Drawing.Drawing2D;
namespace ShareX.ImageEffectsLib
{
@ -54,6 +55,9 @@ public int Size
[DefaultValue(typeof(Color), "Black"), Editor(typeof(MyColorEditor), typeof(UITypeEditor)), TypeConverter(typeof(MyColorConverter))]
public Color Color { get; set; }
[DefaultValue(DashStyle.Solid), TypeConverter(typeof(EnumProperNameConverter))]
public DashStyle DashStyle { get; set; }
[DefaultValue(false)]
public bool UseGradient { get; set; }
@ -79,10 +83,10 @@ public override Bitmap Apply(Bitmap bmp)
{
if (UseGradient && Gradient != null && Gradient.IsValid)
{
return ImageHelpers.DrawBorder(bmp, Gradient, Size, Type);
return ImageHelpers.DrawBorder(bmp, Gradient, Size, Type, DashStyle);
}
return ImageHelpers.DrawBorder(bmp, Color, Size, Type);
return ImageHelpers.DrawBorder(bmp, Color, Size, Type, DashStyle);
}
}
}