我只是想获得 rgb 颜色(#ebfcff)的 rgba 值。rgb 颜色是放在白色背景上时的 rgba。(a 代表阿尔法)
所以:searchedColour + #ffffff = #ebfcff
在我的评估中,解决方案是从#ebfcff 中减去白色。但是你如何减去颜色?
我已经在寻找合适的解决方案。有谁知道如何从给定的 RGB 颜色中减去白色以获得新的颜色,它是 rgba 格式的,当它与白色重叠时等于给定的颜色?
我只是想获得 rgb 颜色(#ebfcff)的 rgba 值。rgb 颜色是放在白色背景上时的 rgba。(a 代表阿尔法)
所以:searchedColour + #ffffff = #ebfcff
在我的评估中,解决方案是从#ebfcff 中减去白色。但是你如何减去颜色?
我已经在寻找合适的解决方案。有谁知道如何从给定的 RGB 颜色中减去白色以获得新的颜色,它是 rgba 格式的,当它与白色重叠时等于给定的颜色?
Colour values aren't just added.
When you plot a colour X
on top of a colour Y
, the value of each colour channel of the resulting colour, C
, is given by:
C = X * a + Y * (a-1)
Using the floating point representation (each channel is a value from 0 to 1); where a
is the alpha channel of X
. (It's easily converted back to 0-255).
For white, Y
is 1 for all channels, so:
C = X * a + (a-1)
So, if a
is 0, you clearly can't find X, which makes sense: If the colour was totally transparent, it makes no difference to the combined colour.
Similarly, if your colour was white (X
=1), you couldn't determine the alpha (the combined colour would be white regardless of the alpha).
Also, you can't find either X
or a
without knowing the other.
If you knew the alpha of the colour, then you could determine what the colour was, but if your combined colour (C
) is a discrete value (such as an integer from 0 to 255), then it is rounded, so you can only get an approximation of the plotted colour (X
). How accurate it is depends on the alpha (the more transparent the plotted colour was, the less accurately you can determine the colour).
So, solving for X:
X * a = C - a - 1
Therefore: X = (C - a - 1 ) / a
For 8-bit colour channels (24-bit colour):
X = 255 * ( C/255 - a/255 - 1 ) / (a/255)
(Given a 6-digit hexadecimal value, apply this for each pair of digits, C
).
You could optimise it to avoid the floating point calculation.
I don't know if that's any use, but that's all you can do.