从两种颜色计算产生的RGB,一种是透明的 [英] Calculate resulting RGB from 2 colors, one is transparent

查看:367
本文介绍了从两种颜色计算产生的RGB,一种是透明的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找一个公式来转换它们。



我知道要转换一般的透明度



alpha * new +(1 - alpha)* old



我有:

 颜色A:RGB(85,113,135)
颜色B:RGB(43,169,225)

颜色A有90%的不透明度,位于颜色B的顶部,导致

  Color C:RGB(65,119,145)

我的问题是,颜色C?



这是另一个例子,同样的基本颜色:

 颜色A:RGB(85,113,135)
颜色B:RGB(45,67,82)
------- -
颜色C:RGB(65,109,131)

与图像 - 我现在计算剩余的颜色C,以便我可以分配背景颜色。






,请看接受的答案。上述例子中的 red 是奇怪的 - 接受的答案有所有颜色的正确的公式,我在Photoshop中测试它。



看来,你的公式正是你的例子中使用的公式,计算每个组件,

R_c:= ceiling(R_a * alpha)+ ceiling(R_b *(1-alpha))

  G_c:= ceiling(G_a * alpha)+ ceiling(G_b *(1-alpha))
B_c:= ceiling(B_a * alpha)+ ceiling(B_b *(1 - alpha))

奇怪的是,R组件似乎不遵循规则。我很想知道为什么。


I'm looking for a formula to convert them.

I know to convert a general transparency it is

alpha * new + ( 1 - alpha ) * old

I have:

Color A : RGB( 85, 113, 135 )
Color B : RGB( 43, 169, 225 )

Color A has 90% opacity and is laid on top of Color B, resulting in

Color C : RGB( 65, 119, 145 )

My question is, how does it get Color C? If I substitute Color B for another thing, how do I get Color C?

Here's another example, same base color:

Color A : RGB( 85, 113, 135 )
Color B : RGB( 45, 67, 82 )
--------
Color C : RGB( 65, 109, 131 )

Those are working examples done with images -- I'm trying to now calculate the remaining Color C so I can assign a background color.


UPDATE, please see the accepted answer. The red in the above examples is strange -- the accepted answer has the correct formula for all the colors, I tested it in Photoshop.

解决方案

It appears that your formula is precisely the formula used in your examples, calculated per component, and rounded up.

R_c := ceiling(R_a * alpha) + ceiling (R_b * (1 - alpha))

G_c := ceiling(G_a * alpha) + ceiling (G_b * (1 - alpha))
B_c := ceiling(B_a * alpha) + ceiling (B_b * (1 - alpha))

Strange, though, the R component doesn't appear to follow the rules. I'm inclined to wonder why.

这篇关于从两种颜色计算产生的RGB,一种是透明的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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