Programmatically Lighten a Color

2020-01-24 03:26发布

Motivation

I'd like to find a way to take an arbitrary color and lighten it a few shades, so that I can programatically create a nice gradient from the one color to a lighter version. The gradient will be used as a background in a UI.

Possibility 1

Obviously I can just split out the RGB values and increase them individually by a certain amount. Is this actually what I want?

Possibility 2

My second thought was to convert the RGB to HSV/HSB/HSL (Hue, Saturation, Value/Brightness/Lightness), increase the brightness a bit, decrease the saturation a bit, and then convert it back to RGB. Will this have the desired effect in general?

20条回答
甜甜的少女心
2楼-- · 2020-01-24 04:18

Method 1: Convert RGB to HSL, adjust HSL, convert back to RGB.

Method 2: Lerp the RGB colour values - http://en.wikipedia.org/wiki/Lerp_(computing)

See my answer to this similar question for a C# implementation of method 2.

查看更多
放荡不羁爱自由
3楼-- · 2020-01-24 04:20

You'll find code to convert between color spaces in the color-tools ruby library

查看更多
登录 后发表回答