Use built in method to create gradient preview

This commit is contained in:
Jaex 2020-08-09 05:11:15 +03:00
parent 3d4e1c952a
commit 00dd733e76
2 changed files with 19 additions and 25 deletions

View file

@ -80,23 +80,6 @@ public void Reverse()
}
}
public void Draw(Graphics g, Rectangle rect)
{
if (IsValid)
{
try
{
using (LinearGradientBrush brush = GetGradientBrush(new Rectangle(0, 0, rect.Width, rect.Height)))
{
g.FillRectangle(brush, rect);
}
}
catch
{
}
}
}
public ColorBlend GetColorBlend()
{
List<GradientStop> colors = new List<GradientStop>(Colors.OrderBy(x => x.Location));
@ -124,15 +107,31 @@ public LinearGradientBrush GetGradientBrush(Rectangle rect)
return brush;
}
public void Draw(Graphics g, Rectangle rect)
{
if (IsValid)
{
try
{
using (LinearGradientBrush brush = GetGradientBrush(new Rectangle(0, 0, rect.Width, rect.Height)))
{
g.FillRectangle(brush, rect);
}
}
catch
{
}
}
}
public Bitmap CreateGradientPreview(int width, int height)
{
Bitmap bmp = new Bitmap(width, height);
Rectangle rect = new Rectangle(0, 0, width, height);
using (Graphics g = Graphics.FromImage(bmp))
using (LinearGradientBrush brush = GetGradientBrush(rect))
{
g.FillRectangle(brush, rect);
Draw(g, rect);
g.DrawRectangleProper(Pens.Black, rect);
}

View file

@ -126,12 +126,7 @@ private void UpdatePreview()
{
if (isReady)
{
Bitmap bmp = new Bitmap(pbPreview.ClientRectangle.Width, pbPreview.ClientRectangle.Height);
using (Graphics g = Graphics.FromImage(bmp))
{
Gradient.Draw(g, new Rectangle(0, 0, bmp.Width, bmp.Height));
}
Bitmap bmp = Gradient.CreateGradientPreview(pbPreview.ClientRectangle.Width, pbPreview.ClientRectangle.Height);
if (pbPreview.Image != null)
{