What code would I use to get the hex value of a color when an alpha at about half transparency is applied?

一个人想着一个人 提交于 2019-12-19 11:43:14

问题


If I have a visual element (could be text or div with color fill, doesn't matter) and the color is set to black, 0x000000, and it's alpha is set to .4 or .5 and the background is solid white, 0xFFFFFF, the result would be a gray color. We can test this in Photoshop.

What I would like to know is what code would I use to get to that result?

I'm looking for something such as an equation:

newColor = foregroundColor * alpha * backgroundColor

Or something like in JavaScript, ActionScript or VBScript:

var color:uint = (0x888888 * .5) * 0x000000;

Part of the difficulty is solving this issue is the lack of fully understanding enough about hexadecimal and how it relates to color to solve it on my own.


回答1:


You can use this Alpha Blending algorithm from wikipedia:



来源:https://stackoverflow.com/questions/14127060/what-code-would-i-use-to-get-the-hex-value-of-a-color-when-an-alpha-at-about-hal

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