Example #1
0
        public HSLStruct(Color color)
        {
            var rgb = new RGBStruct(color);
            var hsl = rgb.ToHSL();

            hue        = hsl.hh;
            saturation = hsl.ss;
            lightness  = hsl.ll;
        }
Example #2
0
        /// <summary>
        /// Apply lightness to an <see cref="RGBStruct"/>
        /// </summary>
        /// <param name="rgb">The <see cref="RGBStruct"/> to edit </param>
        /// <param name="lightness">this param should be between 0.0 and 1.0</param>
        /// <returns></returns>
        public static RGBStruct ApplyLightnessToRGB(RGBStruct @rgb, double lightness)
        {
            try
            {
                var r = rgb.r;
                var g = rgb.g;
                var b = rgb.b;

                var Lpercent = (byte)(lightness * 100);

                var new_r = (byte)((r * Lpercent) / 100);
                var new_g = (byte)((g * Lpercent) / 100);
                var new_b = (byte)((b * Lpercent) / 100);

                return(new RGBStruct(new Color(rgb.a, new_r, new_g, new_b)));
            }
            catch (Exception e)
            {
                throw new Exception("The lightness is greater than 1 or less than 0", e);
            }
        }