简体   繁体   English

将白色混合成一种颜色

[英]Mixing white to a color

I have a set of colors specified in RBG and CMYK. 我有一组在RBG和CMYK中指定的颜色。 I want to mix a certain amount of white (given in percent) to these colors. 我想将一定数量的白色(百分比)添加到这些颜色中。 How can I do this based on the representations available? 如何根据可用的表示执行此操作? Can someone recommend a package that can help me with this kind of color conversions? 有人可以推荐一个可以帮助我进行这种颜色转换的软件包吗?

If you have RGB values r, g and b between 0 and 255 and want to mix them with x% white, you can calculate 如果RGB值r,g和b介于0和255之间,并希望将它们与x%white混合,则可以计算

r' = ((100 - x) * r + x * 255) / 100
g' = ((100 - x) * g + x * 255) / 100
b' = ((100 - x) * b + x * 255) / 100

If you need it to be efficient, there are ways of doing this with efficient bit operations. 如果您需要它是高效的,有很多方法可以通过有效的位操作来实现。

Find the difference between the current color and the target color for each color channel. 找出每个颜色通道的当前颜色和目标颜色之间的差异。 Calculate your percentage of that difference. 计算您的差异百分比。 Add this to the original value, and you're done. 将其添加到原始值,即可完成。

For example, mixing RGB(255,127,0) with RGB(255,255,255) (white) at 75% gives you RGB(255, 223, 191) 例如,将RGB(255,127,0)与RGB(255,255,255)(白色)以75%的比例混合会得到RGB(255,223,191)

  • R: 255-255 = 0 * .75 = 0 + 255 = 255 R:255-255 = 0 * .75 = 0 + 255 = 255
  • G: 255 - 127 = 128 * .75 = 96 + 127 = 224 G:255-127 = 128 * .75 = 96 + 127 = 224
  • B: 255 - 0 = 255 * .75 = 191 + 0 = 191) B:255 - 0 = 255 * .75 = 191 + 0 = 191)

您可以使用此lib将颜色转换为HSL,然后修改L分量并返回到先前的表示形式RGB或CMYK。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM