mirror of
https://github.com/ShareX/ShareX.git
synced 2024-07-01 04:30:49 +12:00
Added multi color gradient support to background image effect
This commit is contained in:
parent
4f2e058260
commit
3dfac10e82
|
@ -700,6 +700,14 @@ public static Bitmap FillBackground(Image img, Color fromColor, Color toColor, L
|
|||
}
|
||||
}
|
||||
|
||||
public static Bitmap FillBackground(Image img, GradientInfo gradientInfo)
|
||||
{
|
||||
using (LinearGradientBrush brush = gradientInfo.GetGradientBrush(new Rectangle(0, 0, img.Width, img.Height)))
|
||||
{
|
||||
return FillBackground(img, brush);
|
||||
}
|
||||
}
|
||||
|
||||
public static Bitmap FillBackground(Image img, Brush brush)
|
||||
{
|
||||
Bitmap result = img.CreateEmptyBitmap();
|
||||
|
|
|
@ -40,22 +40,45 @@ public class DrawBackground : ImageEffect
|
|||
[DefaultValue(false)]
|
||||
public bool UseGradient { get; set; }
|
||||
|
||||
[DefaultValue(LinearGradientMode.Vertical)]
|
||||
public LinearGradientMode GradientType { get; set; }
|
||||
|
||||
[DefaultValue(typeof(Color), "White"), Editor(typeof(MyColorEditor), typeof(UITypeEditor)), TypeConverter(typeof(MyColorConverter))]
|
||||
public Color Color2 { get; set; }
|
||||
|
||||
[DefaultValue(LinearGradientMode.Vertical)]
|
||||
public LinearGradientMode GradientType { get; set; }
|
||||
[DefaultValue(false)]
|
||||
public bool UseCustomGradient { get; set; }
|
||||
|
||||
[Editor(typeof(GradientEditor), typeof(UITypeEditor))]
|
||||
public GradientInfo Gradient { get; set; }
|
||||
|
||||
public DrawBackground()
|
||||
{
|
||||
this.ApplyDefaultPropertyValues();
|
||||
AddDefaultGradient();
|
||||
}
|
||||
|
||||
private void AddDefaultGradient()
|
||||
{
|
||||
Gradient = new GradientInfo();
|
||||
Gradient.Colors.Add(new GradientStop(Color.FromArgb(68, 120, 194), 0f));
|
||||
Gradient.Colors.Add(new GradientStop(Color.FromArgb(13, 58, 122), 50f));
|
||||
Gradient.Colors.Add(new GradientStop(Color.FromArgb(6, 36, 78), 50f));
|
||||
Gradient.Colors.Add(new GradientStop(Color.FromArgb(23, 89, 174), 100f));
|
||||
}
|
||||
|
||||
public override Image Apply(Image img)
|
||||
{
|
||||
if (UseGradient)
|
||||
{
|
||||
return ImageHelpers.FillBackground(img, Color, Color2, GradientType);
|
||||
if (UseCustomGradient && Gradient != null && Gradient.IsValid)
|
||||
{
|
||||
return ImageHelpers.FillBackground(img, Gradient);
|
||||
}
|
||||
else
|
||||
{
|
||||
return ImageHelpers.FillBackground(img, Color, Color2, GradientType);
|
||||
}
|
||||
}
|
||||
|
||||
return ImageHelpers.FillBackground(img, Color);
|
||||
|
|
Loading…
Reference in a new issue