Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/sn4k3/UVtools.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'UVtools.Core/Extensions/DrawingExtensions.cs')
-rw-r--r--UVtools.Core/Extensions/DrawingExtensions.cs34
1 files changed, 34 insertions, 0 deletions
diff --git a/UVtools.Core/Extensions/DrawingExtensions.cs b/UVtools.Core/Extensions/DrawingExtensions.cs
new file mode 100644
index 0000000..8a60ee4
--- /dev/null
+++ b/UVtools.Core/Extensions/DrawingExtensions.cs
@@ -0,0 +1,34 @@
+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;
+ }
+ }
+}