给定 RGB 值,如何创建色调(或阴影)?
给定一个 RGB 值,例如 168, 0, 255
,如何创建颜色的色调(使其更亮)和阴影(使其更暗)?
Given an RGB value, like 168, 0, 255
, how do I create tints (make it lighter) and shades (make it darker) of the color?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
几个用于着色和着色的选项:
对于阴影,将每个分量乘以其颜色的 1/4、1/2、3/4 等
之前的值。系数越小,颜色越深。
对于色调,计算(255 - 先前值),将其乘以 1/4,
1/2、3/4 等(系数越大,色调越浅),并将其与之前的值相加(假设每个组件是 8 位整数)。
请注意,颜色操作(例如色调和其他阴影)应在线性 RGB 中完成。然而,文档中指定的或图像和视频中编码的 RGB 颜色不太可能是线性 RGB,在这种情况下,需要将所谓的逆传递函数应用于 RGB 颜色的每个分量。该函数随 RGB 色彩空间的不同而变化。例如,在 sRGB 颜色空间(如果 RGB 颜色空间未知,则可以假设),此函数大致相当于将每个 sRGB 颜色分量(范围从 0 到 1)的幂2.2. (请注意,“线性 RGB”不是 RGB 颜色空间。)
另请参阅 Violet Giraffe 关于“伽玛校正”的评论。
Among several options for shading and tinting:
For shades, multiply each component by 1/4, 1/2, 3/4, etc., of its
previous value. The smaller the factor, the darker the shade.
For tints, calculate (255 - previous value), multiply that by 1/4,
1/2, 3/4, etc. (the greater the factor, the lighter the tint), and add that to the previous value (assuming each.component is a 8-bit integer).
Note that color manipulations (such as tints and other shading) should be done in linear RGB. However, RGB colors specified in documents or encoded in images and video are not likely to be in linear RGB, in which case a so-called inverse transfer function needs to be applied to each of the RGB color's components. This function varies with the RGB color space. For example, in the sRGB color space (which can be assumed if the RGB color space is unknown), this function is roughly equivalent to raising each sRGB color component (ranging from 0 through 1) to a power of 2.2. (Note that "linear RGB" is not an RGB color space.)
See also Violet Giraffe's comment about "gamma correction".
一些定义
产生阴影
根据您的颜色模型,可以使用不同的方法来创建较暗(阴影)或较亮(有色)颜色:
RGB
:遮光:
着色:
更一般地说,颜色导致颜色
RGB(currentR,currentG,currentB)
与颜色RGBA(aR,aG,aB,alpha)
分层> 是:其中
(aR,aG,aB) = black = (0,0,0)
用于阴影,(aR,aG,aB) = White = (255,255,255)
code> 用于着色HSV
或HSB
:值
/亮度
或提高饱和度
饱和度
或增加值
/亮度
HSL
:亮度
亮度
存在从一种颜色模型转换为另一种颜色模型的公式。根据您最初的问题,如果您处于 RGB 模式并希望使用 HSV 模型进行着色,则只需转换为 HSV 即可,进行着色并转换回
RGB
。转换公式并不简单,但可以在互联网上找到。根据您的语言,它也可能作为核心功能提供:比较模型
RGB
的优点是实现起来非常简单,但是:HSV
或HSB
有点复杂,因为您需要使用两个参数来获得你想要的(Saturation
&Value
/Brightness
)HSL
是最好的我的观点:50%
表示未改变的色调>50%
表示色调较浅(色调)<50%
表示色调较暗(阴影)Lightness
部分)Some definitions
Creating a tint or a shade
Depending on your Color Model, there are different methods to create a darker (shaded) or lighter (tinted) color:
RGB
:To shade:
To tint:
More generally, the color resulting in layering a color
RGB(currentR,currentG,currentB)
with a colorRGBA(aR,aG,aB,alpha)
is:where
(aR,aG,aB) = black = (0,0,0)
for shading, and(aR,aG,aB) = white = (255,255,255)
for tintingHSV
orHSB
:Value
/Brightness
or increase theSaturation
Saturation
or increase theValue
/Brightness
HSL
:Lightness
Lightness
There exists formulas to convert from one color model to another. As per your initial question, if you are in
RGB
and want to use theHSV
model to shade for example, you can just convert toHSV
, do the shading and convert back toRGB
. Formula to convert are not trivial but can be found on the internet. Depending on your language, it might also be available as a core function :Comparing the models
RGB
has the advantage of being really simple to implement, but:HSV
orHSB
is kind of complex because you need to play with two parameters to get what you want (Saturation
&Value
/Brightness
)HSL
is the best from my point of view:50%
means an unaltered Hue>50%
means the Hue is lighter (tint)<50%
means the Hue is darker (shade)Lightness
part)我目前正在尝试画布和像素......我发现这种逻辑更适合我。
添加以抵消“色调”值< /p>
或类似的值...
I'm currently experimenting with canvas and pixels... I'm finding this logic works out for me better.
add to offset the 'tint' value
or something like that...