U
U
unclechu2014-05-18 21:58:30
Mathematics
unclechu, 2014-05-18 21:58:30

How to calculate alpha channel knowing background color and brush color?

Known background color and brush color. Let's say background color: black, brush color: white. 0.5 alpha channel will give the color: 7f7f7f (hexadecimal rgb). How can this be calculated mathematically?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
omo, 2014-05-19
@omo

If I understand correctly, then the answer is here - https://stackoverflow.com/questions/11614940/conve...

alpha = 1 - RGBA.alpha;
RGB.red = Math.round((RGBA.alpha * (RGBA.red / 255) + (alpha * (bg.red / 255))) * 255);
RGB.green = Math.round((RGBA.alpha * (RGBA.green / 255) + (alpha * (bg.green / 255))) * 255);
RGB.blue = Math.round((RGBA.alpha * (RGBA.blue / 255) + (alpha * (bg.blue / 255))) * 255);

Here is the function on Sass sassmeister.com/gist/86d4bcd7a60823f0d3d8

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question