Determine RGBA colour received by combining two colours

不打扰是莪最后的温柔 提交于 2019-11-26 21:37:25

问题


I have two colours defined as RGBA (in my specific examples, one of the set is [white with alpha 0.85] and [57, 40, 28 with alpha 0.25]. The second colour is drawn over the first one (i.e. white with alpha is the background and the second colour is used for drawing). How can I figure out what the RGBA colour of the combination is going to be? I need to do this one-off - so any tools is fine (e.g. I'm happy to draw something in photoshop and see what comes out).

I have several sets to combine, but not too many. Any pointers? Thanks.


回答1:


When using Painter's algorithm most color compositing is done using Porter-Duff "Over" mode:

Resulting alpha:

αr = αa + αb (1 - αa)

Resulting color components:

Cr = (Ca αa + Cb αb (1 - αa)) / αr

So for your example:

alpha = 0.25 + 0.85 * (1 - 0.25)                        = 0.8875

red   = (57 * 0.25 + 255 * 0.85 * (1 - 0.25)) / 0.8875  = 199.2
green = (40 * 0.25 + 255 * 0.85 * (1 - 0.25)) / 0.8875  = 194.4
blue  = (28 * 0.25 + 255 * 0.85 * (1 - 0.25)) / 0.8875  = 191.1

See wikipedia article on alpha compositing.



来源:https://stackoverflow.com/questions/10781953/determine-rgba-colour-received-by-combining-two-colours

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!