简体   繁体   English

为什么将我的灰度 SVG 转换为 alpha 会导致亮度降低?

[英]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: ... 这使:

图1

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: ... 这使:

img2

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.

相关问题 内联svg到灰度 - Inline svg to greyscale 为什么video元素的poster属性会导致我的视​​频偏移? - Why does the poster attribute of the video element cause my video to offset? 为什么 <link> “标题”属性会导致浏览器忽略我的样式? - Why does the <link> ‘title’ attribute cause browsers to ignore my styles? 为什么设置数组元素的值会导致我的脚本失败? - Why does setting the value of an array element cause my script to fail? 为什么这个元素在我的 SVG/CSS/JS 动画中转换为 0,0,0? - Why does this element translate to 0,0,0 in my SVG/CSS/JS animation? 为什么 SVG 过滤器不适用于我的代码中的 HTML 元素? - Why SVG filters does not apply to HTML element in my code? 当嵌套在另一个SVG中时,为什么我的SVG图像被剪切掉而不是调整大小? - Why does my SVG image get cut out rather than resizing when nested inside another SVG? 为什么过滤器:alpha(opacity = 100)破坏了我的打印输出? (IE7和IE8) - Why does filter: alpha(opacity=100) break my printouts? (IE7 & IE8) 为什么我的 SVG 图像可以在 chrome 上完美显示,但当我在 iPhone 上打开它时,它根本不显示? - Why does my SVG image display perfectly on chrome but when I open it on my iPhone it simply does not display? SVG:转换转义的SVG字符串并将其追加到正文不会执行任何操作 - SVG: converting escaped SVG string and appending to body does nothing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM