以数学方式计算不透明度值
不透明度是如何用数学方法计算的?
Photoshop、CSS 等中都有不透明度值。实际上,这种不透明度是图层的透明行为。我们都知道。 但它是如何从数学上计算出来的呢?有没有计算不透明度的公式?
通过设置不透明度值,那里发生了什么?
以纯色图层为例:第 1 层(前景层)和第 2 层(背景层)
第 1 层为红色(例如颜色值 A
),第 2 层为白色(例如颜色值 ) B)。
当我们为第 1 层设置不透明度(例如 p
)时,我们可以设置 0.5 或 50% 并获得白红色(例如颜色值 X
)。
为了获得这个值X
我应该在数学上做什么?
IE。
X = (things which will be a relation containing p, A and B)
我想知道找到 X
的确切数学方程。
另外,如果我有方程,并且颜色值本质上是十六进制,那么使用十六进制计算器我可以获得正确的结果吗?
How is opacity calculated mathematically?
There is opacity value in Photoshop, CSS etc. Actually this opacity is the transparent behavior of a layer. That we all know.
But how is it calculated mathematically? Is there any equation to calculate opacity?
By setting opacity value what is happening there?
Take the case of plain color layers: Layer 1 (Foreground Layer) and Layer 2 (background layer)
Layer 1 is red (say color value A
) and Layer 2 is white (say color value B
).
When we set opacity (say p
) to layer 1, we can put 0.5 or 50% and get a whitish red color (say color value X
).
For getting this value X
what should I do mathematically?
ie.
X = (things which will be a relation containing p, A and B)
I want to know the exact mathematical equation to find X
.
Also if I have the equation, and color values are hexadecimal in nature, so with a hex calculator can I get a correct result?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
合并公式 C1 =
(R1,G1,B1)
和 C2 =(R2,G2,B2)
转换为新颜色 C3,其中 C2 覆盖在 C1 之上,不透明度 p 通常为( (1-p)R1 + p*R2,(1-p)*G1 + p*G2,(1-p)*B1 + p*B2)
。有关详细信息,请参阅有关透明度的维基百科文章。
The formula for combining C1 =
(R1,G1,B1)
and C2 =(R2,G2,B2)
into a new color C3, where C2 is overlayed on top of C1 with opacity p is usually( (1-p)R1 + p*R2, (1-p)*G1 + p*G2, (1-p)*B1 + p*B2 )
.See Wikipedia article on transparency for more information.
下面的javascript给出了一个可以用来手动计算不透明度颜色值的方法:
The following javascript gives a method that can be used to calculate the opacity color value manually:
混合两个透明像素的结果公式:
C1=[R1,G1,B1] 是前景像素颜色。
C2=[R2,G2,B2] 是背景像素颜色。
p1 是前景像素的不透明度百分比。
p2 是背景像素的不透明度百分比。
New_Pixel_Color = (p1*c1+p2*c2-p1*p2*c2)/(p1+p2-p1*p2)
New_Pixel_opacity = p1+p2-p1*p2
您可以测试并享受它!
Formula for Result of mixing two transparent pixels:
C1=[R1,G1,B1] is the foreground pixel color.
C2=[R2,G2,B2] is the background pixel color.
p1 is the opacity percentage of the foreground pixel.
p2 is the opacity percentage of the background pixel.
New_Pixel_Color = (p1*c1+p2*c2-p1*p2*c2)/(p1+p2-p1*p2)
New_Pixel_opacity = p1+p2-p1*p2
You can test and enjoy it!