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

DrawingExtensions.cs « Extensions « UVtools.Core - github.com/sn4k3/UVtools.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 33406a5846d3ca6f7e2bb3a73d7233180e89e8ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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);
        }
    }
}