PROWAREtech
C/C++: Alpha Compositing Algorithm
How to convert an image with an alpha channel to an image without an alpha channel.
Choose Background Color
First, choose a background color to be used for the transparent pixels.
Apply Alpha Compositing Algorithm
The formula for alpha compositing a single pixel typically involves blending each of the RGB values of the foreground image with those of the background color based on the alpha value. The alpha value ranges from 0 (completely transparent) to 255 (completely opaque).
float ConvertAlphaChannelToBackground(float desiredBackgroundColor, float foregroundColor, float alpha)
{
return (foregroundColor * alpha / 255) + (desiredBackgroundColor * (255 - alpha) / 255);
}
Comment