Method GetBrighterColor
GetBrighterColor(double)
Returns a color with the same hue and saturation as this color, but with a significantly different lightness, making it suitable for use as a highlight or contrast color in UI elements.
public Color GetBrighterColor(double brightenAmount = 0.2)
Parameters
brightenAmount
doubleThe percent amount to brighten the color by. The default is
20%
.
Returns
- Color
A Color instance with the same hue and saturation as this color, but with a contrasting lightness.
Examples
var baseColor = new Color(100, 100, 100);
var highlight = baseColor.GetHighlightColor();
// highlight will be a lighter or darker version of baseColor, depending on its original lightness.
Remarks
This method brightens the color if it is dark, or darkens it if it is light, ensuring the result is visually distinct from the original. The algorithm works in HSL color space and adjusts the lightness channel:
- If the color is dark (lightness < 0.5), the lightness is increased (brightened).
- If the color is light (lightness >= 0.5), the lightness is decreased (darkened).
- If the adjustment resulted in a color too close to the original, a larger adjustment is made.
The returned color will always have the same hue and saturation as the original, but a different lightness.