Change Color Shade - CSharp System.Drawing

CSharp examples for System.Drawing:Color

Description

Change Color Shade

Demo Code


using Windows.UI;
using System.Threading.Tasks;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;//  w  w  w  . j a va  2s.  c o  m

public class Main{
        // Change the shade of a given color by adding a value to the lightness.
        public static Color ChangeShade(Color colorToChange, float value)
        {
            // Convert color to HSL
            HSL temp = RGB2HSL(colorToChange);

            // Change the lightness value
            temp.Lightness += value;

            // Check that light it still in range [0,1],
            // else correct it
            if (temp.Lightness > 1)
            {
                temp.Lightness = 1;
            }
            else if (temp.Lightness < 0)
            {
                temp.Lightness = 0;
            }

            // Return the new RGB Color
            return HSL2RGB(temp);
        }
}

Related Tutorials