I have a base color code (in this example it is "#0078D4") either in hexadecimal or RGB. Keeping this as base, I need to generate lighter and darker gradient colors based on %percentage. Is there any C# code or algorithm there to achieve this?
#004478 | Darken 18% | rgb(0,68,120)
#005ba1 | Darken 10% | rgb(0,91,161)
#006fc5 | Darken 3% | rgb(0,111,197)
#0078D4 | rgb(0,120,212) |
#0086ed | Lighten 5% | rgb(0,134,237)
#4fb3ff | Lighten 24% | rgb(79,179,255)
#bae1ff | Lighten 46% | rgb(186,225,255)
# d9efff | Lighten 51% | rgb(217,239,255)
# edf7ff | Lighten 55% | rgb(237,247,255)
in System.Drawing
you can use:
Color color = Color.FromArgb(r, g, b);
var h = color.GetHue();
var s = color.GetSaturation();
var l = color.GetBrightness(); <-- increase or decrease
in System.Windows.Forms
you can use the
`ControlPaint.Light/Dark Method
var result = ColorPaint.Dark(rgb(0,68,120), .18);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.