Exemple #1
0
        public static System.Drawing.Color BrightnessChange(this System.Drawing.Color color, double Brightness)
        {
            var c  = ToHSL(color);
            var lc = MathTool.Map(MathTool.Constrain(Brightness, -1, 1), -1, 1, 0, 1);

            c.L = lc;
            return(c.ToRGB());
        }
Exemple #2
0
        public static System.Drawing.Color BrightnessTransmit(this System.Drawing.Color color, double Brightness)
        {
            var c  = ToHSL(color);
            var lc = MathTool.Constrain(c.L * Brightness, -1, 1);

            c.L = MathTool.Constrain(c.L + lc, 0, 1);
            return(c.ToRGB());
        }
Exemple #3
0
        public System.Drawing.Color ToRGB()
        {
            var hue        = MathTool.Constrain(H, 0, 360);
            var saturation = MathTool.Constrain(S, 0, 1);
            var value      = MathTool.Constrain(V, 0, 1);
            var alpha      = MathTool.Constrain(A, 0, 1);

            double chroma = value * saturation;
            double h1 = hue / 60.0;
            double x = chroma * (1.0 - Math.Abs((h1 % 2.0) - 1.0));
            double m = value - chroma;
            double r1, g1, b1;

            if (h1 < 1)
            {
                r1 = chroma;
                g1 = x;
                b1 = 0;
            }
            else if (h1 < 2)
            {
                r1 = x;
                g1 = chroma;
                b1 = 0;
            }
            else if (h1 < 3)
            {
                r1 = 0;
                g1 = chroma;
                b1 = x;
            }
            else if (h1 < 4)
            {
                r1 = 0;
                g1 = x;
                b1 = chroma;
            }
            else if (h1 < 5)
            {
                r1 = x;
                g1 = 0;
                b1 = chroma;
            }
            else
            {
                r1 = chroma;
                g1 = 0;
                b1 = x;
            }

            byte r = (byte)Math.Round(255.0 * (r1 + m));
            byte g = (byte)Math.Round(255.0 * (g1 + m));
            byte b = (byte)Math.Round(255.0 * (b1 + m));
            byte a = (byte)Math.Round(255.0 * alpha);

            return(System.Drawing.Color.FromArgb(a, r, g, b));
        }