2017-07-21 36 views
0

我正在與一個HTMLcanvas元素,試圖繪製不透明的形狀,然後根據它們的不透明度對它們着色。例如,我可能畫一個正方形rgba(0,0,0,.5),另一個與rgba(100, 100, 100, .5)重疊。我的問題是:重疊對alpha值有什麼影響?顯然,在a:.5之上的a:.5不會產生a:1 ...是否有這樣的公式?它是如何工作的?RGBA像素阿爾法值在畫布中

+0

他們不是簡單地(反轉)相乘,所以'0.5×0.5 = .25',和合並的不透明性變得'1-。 25 = .75'? – myfunkyside

+1

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

+0

這使得總體感覺,爲什麼它不會發生在我身上......我不知道 – WookieCoder

回答

1

所有如何alpha混合和組合物作品可以在規範中找到公式:

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

阿爾法信道相乘(見在該鏈接的阿爾法混合式),所以它們將不添加最多爲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