1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
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);
}
}
}
|