Convert RGBA To HEX


Answer :

Since alpha value both attenuates the background color and the color value, something like this could do the trick:


function rgba2rgb(RGB_background, RGBA_color)
{
var alpha = RGBA_color.a;

return new Color(
(1 - alpha) * RGB_background.r + alpha * RGBA_color.r,
(1 - alpha) * RGB_background.g + alpha * RGBA_color.g,
(1 - alpha) * RGB_background.b + alpha * RGBA_color.b
);
}

(Try it interactively: https://marcodiiga.github.io/rgba-to-rgb-conversion)



Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable