Files
UVtools/UVtools.Core/Extensions/DrawingExtensions.cs
T
Tiago Conceição f4e2ad4daa (#63)
* (Add) Pixel Editor: Erase drawing edits while hold Control (#63)
* (Add) Pixel Editor: When using diameters larger than 1px and when possible the cursor will show the associated drawing preview (#63)
* (Fix) Pixel Editor: Area px<sup>2</sup> to Diameter px (#63)
2020-09-19 01:56:02 +01:00

40 lines
1.2 KiB
C#

using System;
using System.Drawing;
namespace UVtools.Core.Extensions
{
public static class DrawingExtensions
{
public static Color FactorColor(this Color color, byte pixelColor, byte min = 0, byte max = byte.MaxValue) =>
FactorColor(color, pixelColor / 255f, min, max);
public static Color FactorColor(this Color color, float factor, byte min = 0, byte max = byte.MaxValue)
{
byte r = (byte)(color.R == 0 ? 0 :
Math.Min(Math.Max(min, color.R * factor), max));
byte g = (byte)(color.G == 0 ? 0 :
Math.Min(Math.Max(min, color.G * factor), max));
byte b = (byte)(color.B == 0 ? 0 :
Math.Min(Math.Max(min, color.B * factor), max));
return Color.FromArgb(r, g, b);
}
public static int GetArea(this Rectangle rect)
{
return rect.Width * rect.Height;
}
public static int GetArea(this Size size)
{
return size.Width * size.Height;
}
public static int GetMaximum(this Size size)
{
return Math.Max(size.Width, size.Height);
}
}
}