C#: Create a lighter/darker color based on a system color

前端 未结 11 1400
春和景丽
春和景丽 2020-12-07 18:26

Duplicate

How do I adjust the brightness of a color?
How do I determine darker or lighter color variant of a given color?
Programmat

11条回答
  •  一整个雨季
    2020-12-07 18:55

    Most of these methods do darken the color but they adjust the hue way to much so the result doesn't look very good. The best answer is to use Rich Newman's HSLColor class and adjust the luminosity.

    public Color Darken(Color color, double darkenAmount) {
        HSLColor hslColor = new HSLColor(color);
        hslColor.Luminosity *= darkenAmount; // 0 to 1
        return hslColor;
    }
    

提交回复
热议问题