How to change the alpha of a pixel without changing the resulting color?

瘦欲@ 提交于 2020-02-04 11:36:39

问题


Given: A pixel, with its color (denoted as PC0) and alpha value (denoted as PA0), which is layered over a background of some color (denoted as BC).

Question: How would you change the alpha value of the pixel (PA0) for another value (denoted as PA1) so that the resulting composite color of the pixel and the background does not change (PBC0 == PBC1)? In other words, how would you find such PC1 that makes the original and resulting composite colors (PBC0 and PBC1) look identical?


回答1:


PBC0 = PC0*PA0 + BC*(1-PA0)
     = PC1*PA1 + BC*(1-PA1)

If you know both PA0 and PA1, you can solve for PC1.

PC1 = (PC0*PA0 + BC*(1-PA0) - BC*(1-PA1)) / PA1

Edit: substitute 255 for 1 in the above if you're using the common convention of color values ranging from 0-255.



来源:https://stackoverflow.com/questions/9282714/how-to-change-the-alpha-of-a-pixel-without-changing-the-resulting-color

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!