mirror of
https://github.com/ShareX/ShareX.git
synced 2024-09-30 01:07:21 +13:00
Use built in method to create gradient preview
This commit is contained in:
parent
3d4e1c952a
commit
00dd733e76
2 changed files with 19 additions and 25 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue