I have RGB color value and alpha value. How can I get new RGB value assuming that I have white backgound and alpha is applied?
Asked
Active
Viewed 1,819 times
1 Answers
14
The formula to be applied to each of the color channels is the following:
cr = cf * af + cb * ab * (1 - af)
where cr is the resulting color of the pixel, cf is the foreground color, cb the background color, af foreground alpha and ab background alpha.
Note that often color values are stored already premultiplied by alpha in which case the formula simplifies to
cr = cf + cb * (1 - af)
See also alpha composing.

Adam Zalcman
- 26,643
- 4
- 71
- 92
-
Assume I have red color (ff0000) with alpha 0.5, and the background is white. Trying to get result color: ff0000*0.5 + ffffff*0.5 = ff7fff, but this is not what I expect... http://www.colorhexa.com/ff7fff What am I doing wrong? – Timofei Davydik Jul 12 '12 at 09:02
-
2Apply the formula to each color individually (red, green, blue) – Aaron Digulla Jul 12 '12 at 09:16
-
What about the alpha channel of the new color? – Sebastian Barth Oct 26 '16 at 11:11