COOLGAMETUBE COOLGAMETUBE - 1 year ago 123 Question

Calculate color of an Pixel for a transparent application background image

I use VB for my application and have a rounded Background Image including logo. Its also a bit anisotropic anisalized to prevent a sharp Logo. Because vb only allows color key-ing without any tolerance I have to replace the pixels with an Alpha value to an Pixel without one. In a nutshell I have to combine the Pixel of the screen with the Pixel of the background image. But the Problem is: I don't know the formula to get the result color of the Pixel.

Answer Source

This is called "Alpha Compositing" You can use the following equations, courtesy of the wikipedia page (click here), to get the resulting RGB values from two transparent RGB images. (only one has to be transparent, so the other one can be your screen/background with 100% alpha.)

These equations assume that you have one transparent object on top of another object, where R1 is the Red component of object #1, a1 is the alpha of object #1, and so on and so forth...

I'll show the highlights below

R = (R1 * a1 / 255) + (R2 * a2 * (255 - a1) / (255^2))
G = (G1 * a1 / 255) + (G2 * a2 * (255 - a1) / (255^2))
B = (B1 * a1 / 255) + (B2 * a2 * (255 - a1) / (255^2))
Alpha = a1 + (a2 * (255 - a1) / 255)

I also recommend skimming the wiki page because it's quite fascinating.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download