以编程方式淡化颜色 [英] Programmatically Lighten a Color

查看:187
本文介绍了以编程方式淡化颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

动机

我想找到一种方法,可以采取任意颜色和减少几个阴影,程序化地创建从一种颜色到较轻版本的漂亮渐变。渐变将用作用户界面中的背景。

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.

可能性1

显然,我可以分割出RGB值,并单独增加一定量。这实际上是我想要的吗?

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

可能性2

将RGB转换为HSV / HSB / HSL(色相,饱和度,值/亮度/亮度),增加亮度一点,逐渐降低饱和度,然后将其转换回RGB。这会有一般的期望效果吗?

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?

推荐答案

我会去第二个选项。一般来说,RGB空间对于颜色操作(创建从一种颜色到另一种颜色的过渡,淡化/变暗颜色等)并不是很好。下面是两个网站,我发现与快速搜索转换/到RGB /从HSL:

I would go for the second option. Generally speaking the RGB space is not really good for doing color manipulation (creating transition from one color to an other, lightening / darkening a color, etc). Below are two sites I've found with a quick search to convert from/to RGB to/from HSL:

  • from the "Fundamentals of Computer Graphics"
  • some sourcecode in C# - should be easy to adapt to other programming languages.

这篇关于以编程方式淡化颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆