【问题标题】:RGBA Pixel Addition Alpha Value in Canvas画布中的 RGBA 像素加法 Alpha 值
【发布时间】:2017-12-27 21:22:26
【问题描述】:

我正在使用 HTML canvas 元素,尝试在其中绘制具有不透明度的形状,然后根据它们的不透明度为它们着色。例如,我可能会用rgba(0,0,0,.5) 绘制一个正方形,而另一个用rgba(100, 100, 100, .5) 重叠它。我的问题是:重叠对alpha 值有什么影响?显然,a:.5 上面的 a:.5 不会产生 a:1... 有这个公式吗?它是如何工作的?

【问题讨论】:

标签: html canvas alpha


【解决方案1】:

关于 alpha 混合和合成如何工作的所有公式都可以在规范中找到:

https://drafts.fxtf.org/compositing-1/#canvascompositingandblending

Alpha 通道相乘(请参阅链接中的 Alpha 混合公式),因此它们加起来不会等于 1。

即(来源:同上):

co = Cs x αs + Cb x αb x (1 - αs)

在哪里

co: the premultiplied pixel value after compositing
Cs: the color value of the source graphic element being composited
αs: the alpha value of the source graphic element being composited
Cb: the color value of the backdrop
αb: the alpha value of the backdrop 

【讨论】:

    猜你喜欢
    • 2012-02-23
    • 2021-12-17
    • 1970-01-01
    • 2020-07-11
    • 2016-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-20
    相关资源
    最近更新 更多