Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simulate color transparency

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?

like image 890
Timofei Davydik Avatar asked Jul 12 '12 08:07

Timofei Davydik


People also ask

Can RGB represent transparency?

rgb() The rgb() functional notation expresses a color according to its red, green, and blue components. An optional alpha component represents the color's transparency.

How do you make an illusion of transparency?

The impression of transparency can be achieved when two sets of color are joined by a third that is perfectly balanced between them. Split the difference between the luminosity, hue, and saturation of the two to arrive at the third.

What is simulated transparency?

Simulated Transparency - A color illusion in which opaque media is used to create an illusion of transparency.

How do I make RGB transparent?

Make transparent colors in RThe rgb() command is the key: you define a new color using numerical values (0–255) for red, green and blue. In addition, you set an alpha value (also 0–255), which sets the transparency (0 being fully transparent and 255 being “solid”).


1 Answers

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.

like image 137
Adam Zalcman Avatar answered Sep 27 '22 16:09

Adam Zalcman