Http://blog.csdn.net/xhhjin/article/details/6445460
Alpha transparency MixingAlgorithmTo collect and organize data online, which can be divided into the following three types:
1. R1, G1, B1, and alpha1 are foreground color values. R2, G2, B2, and alpha2 are background color values.
Foreground r = R1 * alpha1 + R2 * alpha2 * (1-alpha1 );
G = G1 * alpha1 + G2 * alpha2 * (1-alpha1 );
B = b1 * alpha1 + B2 * alpha2 * (1-alpha1 );
Background Color alpha = 1-(1-alpha1) * (1-alpha2 );
R = r/Alpha;
G = g/Alpha;
B = B/Alpha;
Ii. translucent algorithm:
Currently, alphablend is a common hybrid algorithm.
The calculation formula is as follows: assume that one image is a and the other transparent image is B. Then, through B, the image C looks like a is a hybrid image of B and,
Set the transparency of Image B to alpha (the value 0-is completely transparent, and 0 is completely opaque ).
The Alpha mixing formula is as follows:
R (c) = (1-alpha) * R (B) + Alpha * R ()
G (c) = (1-alpha) * g (B) + Alpha * g ()
B (c) = (1-alpha) * B (B) + Alpha * B ()
R (x), g (x), and B (X) indicate the primary colors of the RGB component. As you can see from the above formula, Alpha is actually a value that determines the transparency of the mixture.
You can change the Alpha value to get a gradient.
Separating RGB colors using "bitwise AND" and "shift" operations;
The transparent ratio is classified by the power of 2, which allows quick calculation.
For 32-level
Alpha = 1/32.
Graph B's Weight = (32-N)/32, then Graph A's Weight = N/32,
The following algorithm can be obtained:
R (c) = (32-n) * R (B) + N * R ();
Then you can shift the right of R (c) to 5 places (divided by 32 ).
Transparent processing:
Assume that the black transparent color on B is specified, and the color on B is black, then the black color is not displayed, instead, the color at the position on a is displayed.
Iii. Simple Alpha hybrid algorithm: First, you must be able to obtain the RGB color of the upper and lower layers,
Then, R, G, and B are used as the final color values. R1, G1, and B1 are the upper color values; r2, G2, and b2 are the lower color values.
If alpha = transparency, then
When alpha = 50%,
R = R1/2 + R2/2;
G = G1/2 + G2/2;
B = b1/2 + b2/2;
When Alpha <50%,
R = R1-R1/Alpha + R2/Alpha;
G = G1-G1/Alpha + G2/Alpha;
B = B1-B1/Alpha + b2/Alpha;
When alpha> 50%,
R = R1/Alpha + R2-R2/Alpha;
G = G1/Alpha + G2-G2/Alpha;
B = b1/Alpha + B2-B2/Alpha;