当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


SVG <feFuncB>用法及代码示例


SVG 代表可缩放矢量图形。它可以用来制作图形和动画,就像在 HTML 画布中一样。 SVG 自 1999 年起由万维网联盟 (W3C) 开发。

SVG <feFunB> 元素:这些元素通常是<feComponentTransfer>并指定其父 <feComponentTransfer> 元素的输入图形的蓝色分量的传递函数。

用法:

<feComponentTransfer>       
    <feFuncB type="" tableValues=""/>
</feComponentTransfer>

属性:它没有任何指定的属性,但它接受全局属性。

示例 1:以下代码演示了类型为 “table” 的 <feFuncB> 元素。

HTML


<!DOCTYPE html> 
<html> 
  
<head> 
    <title>SVG feFuncB Element</title> 
</head> 
  
<body> 
    <svg width="640" height="550" 
        viewBox="0 0 640 550"> 
          
        <defs> 
            <filter id="new" 
                filterUnits="objectBoundingBox" 
                x="0%" y="0%" width="100%" 
                height="100%"> 
  
                <feComponentTransfer> 
                    <feFuncB type="table" 
                        tableValues="1 1 0 0" /> 
                </feComponentTransfer> 
            </filter> 
        </defs> 
  
        <image x="10" y="10" width="280" 
            height="350" 
            preserveAspectRatio="true"
            xlink:href= 
"https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-19.png" /> 
        <image x="310" y="10" width="280" 
            height="350" preserveAspectRatio="true" 
            filter="url(#new)"
            xlink:href= 
"https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-19.png" /> 
    </svg> 
</body> 
  
</html>

输出:

示例 2:以下代码演示了类型为 “gamma” 的 <feFuncB> 元素。

HTML


<!DOCTYPE html> 
<html> 
  
<head> 
    <title>SVG feFuncB Element</title> 
</head> 
  
<body> 
    <svg width="640" height="550" 
        viewBox="0 0 640 550"> 
        <defs> 
            <filter id="new" 
                filterUnits="objectBoundingBox" 
                x="0%" y="0%" width="100%" 
                height="100%"> 
                <feComponentTransfer 
                    in="BackgroundImage" 
                    result="A"> 
                    <feFuncB type="gamma" 
                        amplitude="0" eponent="1" 
                        offset="0.5" /> 
                </feComponentTransfer> 
            </filter> 
        </defs> 
  
        <image x="10" y="10" width="280" 
            height="350" 
            preserveAspectRatio="true"
            xlink:href= 
"https://media.geeksforgeeks.org/wp-content/cdn-uploads/20200817185016/gfg_complete_logo_2x-min.png" /> 
        <image x="310" y="10" width="280" 
            height="350" 
            preserveAspectRatio="true" 
            filter="url(#new)"
            xlink:href= 
"https://media.geeksforgeeks.org/wp-content/cdn-uploads/20200817185016/gfg_complete_logo_2x-min.png" /> 
    </svg> 
</body> 
  
</html>

输出:

示例 3:以下代码演示了类型为 “discrete” 的 <feFuncG> 元素,并且使用值设置了诸如 “amplitude”,”exponent”,”offset” 之类的属性。

HTML


<!DOCTYPE html> 
<html> 
  
<head> 
    <title>SVG feFuncB Element</title> 
</head> 
  
<body> 
    <svg width="640" height="550" 
        viewBox="0 0 640 550"> 
        <defs> 
            <filter id="new" 
                filterUnits="objectBoundingBox" 
                x="0%" y="0%" 
                width="100%" height="100%">       
                 
                <feComponentTransfer 
                    in="BackgroundImage" result="A">             
                    <feFuncB type="discrete" 
                        tableValues="1 0 0 0"/>               
                </feComponentTransfer>  
            </filter> 
        </defs> 
          
        <image x="10" y="10" width="280" 
            height="350" 
            preserveAspectRatio="true" 
            xlink:href= 
"https://media.geeksforgeeks.org/wp-content/uploads/20210915115837/gfg3-300x300.png"/> 
        <image x="310" y="10" width="280" 
            height="350" 
            preserveAspectRatio="true" 
            filter="url(#new)" 
            xlink:href= 
"https://media.geeksforgeeks.org/wp-content/uploads/20210915115837/gfg3-300x300.png"/> 
    </svg> 
</body> 
  
</html>

输出:



相关用法


注:本文由纯净天空筛选整理自rudrakshladdha大神的英文原创作品 SVG <feFuncB> Element。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。