mirror of
https://github.com/riegera2412/UVtools.git
synced 2026-07-11 11:02:32 +02:00
f4e2ad4daa
* (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)
40 lines
1.2 KiB
C#
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);
|
|
}
|
|
}
|
|
}
|