<feComposite>
<feComposite>
SVG 滤镜图元使用 Porter-Duff 合成操作之一,逐像素地在图像空间中组合两个输入图像:over
、in
、atop
、out
、xor
、lighter
或 arithmetic
。
与其它滤镜图元一样,它默认在 linearRGB
颜色空间中处理颜色分量。您可以使用 color-interpolation-filters
属性改为使用 sRGB
。
下表展示了使用 MDN 徽标图像与红色圆圈合成的每种操作:
操作 | 描述 |
---|---|
over |
由 in 属性定义的源图形(MDN 徽标)放置在由 in2 属性定义的目标图形(圆圈)之上。这是默认操作,如果未指定操作或指定了不受支持的操作,则将使用此操作。 |
in |
由 in 属性定义的源图形与由 in2 属性定义的目标图形重叠的部分,替换目标图形。 |
out |
由 in 属性定义的源图形中,不与由 in2 属性定义的目标图形重叠的部分,将被显示。 |
atop |
由 in 属性定义的源图形中,与由 in2 属性定义的目标图形重叠的部分,替换目标图形。不与源图形重叠的目标图形部分保持不变。 |
xor |
由 in 属性定义的源图形和由 in2 属性定义的目标图形的非重叠区域被组合。 |
lighter |
显示由 in 属性定义的源图形和由 in2 属性定义的目标图形的像素值之和。 |
arithmetic |
result = k1*i1*i2 + k2*i1 + k3*i2 + k4 其中 |
使用语境
属性
DOM 接口
此元素实现了 SVGFECompositeElement
接口。
示例
此示例定义了支持的每种操作(over
、atop
、lighter
等)的滤镜,它们将输入 SourceGraphic
与 MDN 徽标图像合成。这些滤镜分别应用于一个圆圈元素,该圆圈元素随后被用作 SourceGraphic
。
注意:在现代浏览器中,BackgroundImage
不能用作合成源,因此我们无法定义一个滤镜来使用恰好位于滤镜下方的任何像素作为源之一进行合成。这里采用的方法是 BackgroundImage
的解决方法,因为我们无法使用 BackgroundImage
。
SVG
html
<svg
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<filter id="imageOver">
<feImage href="mdn_logo_only_color.png" x="10px" y="10px" width="160px" />
<feComposite in2="SourceGraphic" operator="over" />
</filter>
<filter id="imageIn">
<feImage href="mdn_logo_only_color.png" x="10px" y="10px" width="160px" />
<feComposite in2="SourceGraphic" operator="in" />
</filter>
<filter id="imageOut">
<feImage href="mdn_logo_only_color.png" x="10px" y="10px" width="160px" />
<feComposite in2="SourceGraphic" operator="out" />
</filter>
<filter id="imageAtop">
<feImage href="mdn_logo_only_color.png" x="10px" y="10px" width="160px" />
<feComposite in2="SourceGraphic" operator="atop" />
</filter>
<filter id="imageXor">
<feImage href="mdn_logo_only_color.png" x="10px" y="10px" width="160px" />
<feComposite in2="SourceGraphic" operator="xor" />
</filter>
<filter id="imageArithmetic">
<feImage href="mdn_logo_only_color.png" x="10px" y="10px" width="160px" />
<feComposite
in2="SourceGraphic"
operator="arithmetic"
k1="0.1"
k2="0.2"
k3="0.3"
k4="0.4" />
</filter>
<filter id="imageLighter">
<feImage href="mdn_logo_only_color.png" x="10px" y="10px" width="160px" />
<feComposite in2="SourceGraphic" operator="lighter" />
</filter>
</defs>
<g transform="translate(0,25)">
<circle
cx="90px"
cy="80px"
r="70px"
fill="#cc0000"
filter="url(#imageOver)" />
<text x="80" y="-5">over</text>
</g>
<g transform="translate(200,25)">
<circle
cx="90px"
cy="80px"
r="70px"
fill="#cc0000"
filter="url(#imageIn)" />
<text x="80" y="-5">in</text>
</g>
<g transform="translate(400,25)">
<circle
cx="90px"
cy="80px"
r="70px"
fill="#cc0000"
filter="url(#imageOut)" />
<text x="80" y="-5">out</text>
</g>
<g transform="translate(600,25)">
<circle
cx="90px"
cy="80px"
r="70px"
fill="#cc0000"
filter="url(#imageAtop)" />
<text x="80" y="-5">atop</text>
</g>
<g transform="translate(0,240)">
<circle
cx="90px"
cy="80px"
r="70px"
fill="#cc0000"
filter="url(#imageXor)" />
<text x="80" y="-5">xor</text>
</g>
<g transform="translate(200,240)">
<circle
cx="90px"
cy="80px"
r="70px"
fill="#cc0000"
filter="url(#imageArithmetic)" />
<text x="70" y="-5">arithmetic</text>
</g>
<g transform="translate(400,240)">
<circle
cx="90px"
cy="80px"
r="70px"
fill="#cc0000"
filter="url(#imageLighter)" />
<text x="80" y="-5">lighter</text>
</g>
</svg>
结果
规范
规范 |
---|
滤镜效果模块第 1 级 # feCompositeElement |
浏览器兼容性
加载中…