3

So I have color "B" at 100% opacity. I need a way of finding the color "A" that looks exactly the same as the above when it is at 90% opacity.

Assume that background is pure white but I don't think that matters as long as it's the same color on both instances.

How can this be done?

5

Result of normal alpha blending is:

Cout = α * CFG+(1-α) * CBG

where CFG is the foreground color and CBG is the background color and α is the opacity. Thus you want to solve A from equation:

B = 0.9 * A + (1-0.9) * CBG

Which after manipulation is:

A = (B - 0.1 * CBG) / 0.9

further assuming white color the formula per color channel is:

A = (B - 0.1) / 0.9

While this is the general answer, there is a big caveat associated with this calculation. This does not account for any color management. So you might need to convert the color to linear and then back to the original color space to do this calculation. There is also a second consideration to think about: The color you may need to use can exit the displayable gamut of your system.

  • What's that in English? – GeorgeWL Jun 12 '16 at 11:18
  • 1
    @TheGeorgeL which part? – joojaa Jun 14 '16 at 18:30
  • Well let's say that for some crazy reason you're only able to work in hex colours, how would that be found from this math? – GeorgeWL Jun 14 '16 at 18:32
  • 1
    Extract the hex value of one color channel as a number, then you divide your hex color by 255 use formulas to calculate and multiply by result 255 convert back to hex. repeat for 2 other channels. – joojaa Jun 14 '16 at 18:40
  • Ooh, that's far simpler than I expected. – GeorgeWL Jun 14 '16 at 18:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.