[英]Why does converting my greyscale SVG to alpha cause a reduction in brightness?
I'm trying to create a transparent "starry night" effect with an SVG.我正在尝试使用 SVG 创建一个透明的“星夜”效果。 I have my SVG inlined on a webpage, inside an element with a black background.我将 SVG 内联在网页上,在黑色背景的元素内。 I start out with a turbulence filter, then apply a color matrix to get the desired effect:我从湍流过滤器开始,然后应用颜色矩阵以获得所需的效果:
<svg xmlns="http://www.w3.org/2000/svg">
<filter id="filter">
<feTurbulence baseFrequency="0.2" />
<feColorMatrix values="
0 0 0 1 -.5
0 0 0 1 -.5
0 0 0 1 -.5
0 0 0 0 1" />
</filter>
<rect width="100%" height="100%" filter="url(#filter)" />
</svg>
... which gives: ... 这使:
But this has no alpha transparency;但这没有 alpha 透明度; I want this to represent a plane of white pixels whose brightness is reduced only by being on a black background and having less opacity.我希望它代表一个白色像素平面,其亮度仅通过位于黑色背景上且不透明度较低而降低。 So I put it through a second filter to do this:所以我把它通过第二个过滤器来做到这一点:
<svg xmlns="http://www.w3.org/2000/svg">
<filter id="filter">
<feTurbulence baseFrequency="0.2" />
<feColorMatrix values="
0 0 0 1 -.5
0 0 0 1 -.5
0 0 0 1 -.5
0 0 0 0 1" />
<feColorMatrix values="
0 0 0 0 1
0 0 0 0 1
0 0 0 0 1
1 1 1 0 0" />
</filter>
<rect width="100%" height="100%" filter="url(#filter)" />
</svg>
... which gives: ... 这使:
This is very similar, but slightly darker.这非常相似,但稍暗。 Why is it slightly darker?为什么颜色稍微深一点? Shouldn't it logically produce identical pixel colours when overlayed on a black background?当覆盖在黑色背景上时,它不应该在逻辑上产生相同的像素颜色吗?
As Robert notes above, there is some weirdness produced by color space conversions.正如 Robert 上面提到的,色彩空间转换会产生一些奇怪的现象。 Pixels should actually be brighter after the second colormatrix.在第二个颜色矩阵之后,像素实际上应该更亮。 It looks like you can fix this by adding an additional feComponentTransfer with SQRT(1/2.2) as the exponent value.看起来您可以通过添加一个以 SQRT(1/2.2) 作为指数值的附加 feComponentTransfer 来解决此问题。
<filter id="filter" >
<feTurbulence baseFrequency="0.2" />
<feColorMatrix type="matrix" values="
0 0 0 1 -.5
0 0 0 1 -.5
0 0 0 1 -.5
0 0 0 0 1" />
<feColorMatrix type="matrix" values="
0 0 0 0 1
0 0 0 0 1
0 0 0 0 1
1 1 1 0 0" />
<feComponentTransfer>
<feFuncA type="gamma" exponent="0.674"/>
</feComponentTransfer>
</filter>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.