问题描述
我在写一个颜色选择器,从屏幕上的任何地方获取像素RGB值。我想也有选择指定我选择的颜色已经有一个alpha值。我只是想知道如何计算所得的颜色。
I'm writing a colour picker that gets the pixel RGB values from wherever you point to on the screen. I want to also have the option of specifying that the colour I picked already has an alpha value. I'm just wondering how I can calculate the resulting colour.
例如:
是240,247,249,但我知道原来的颜色有10%的不透明度,并在一个白色(255,255,255)背景的顶部。
The resulting pixel colour is 240,247,249 but I know that the original colour had a 10% opacity and was on top of a white (255,255,255) background. What's the calculation to work out the original RGB values?
推荐答案
标准混合方程是:
out = alpha * new + (1 - alpha) * old
$ b b
其中 out
, new
和 old
是RGB颜色, alpha
是范围[0,1]中的浮点数。
Where out
, new
and old
are RGB colors, and alpha
is a floating point number in the range [0,1].
所以,你有(红色):
240 = 0.1 * newR + 0.9 * 255
解决 newR
,我们得到:
newR = (240 - 0.9 * 255) / 0.1
b $ b
其值为105.对其他组件重复,完成。
which evaluates to 105. Repeat for the other components, and you're done.
这篇关于如何通过指定Alpha混合量来计算RGB颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!