c# - 如何使用 svg .net 添加蒙版?

标签 c# .net svg line mask

我不知道如何像这样使用 svg .net 将掩码添加到一行:

<svg height="210" width="500">
    <mask id="myMask">`
       <rect x="0" y="0" width="50" height="50" fill="white" />
    <rect x="170" y="150" width="50" height="50" fill="white" />
    </mask>      
    <line x1="0" y1="0" x2="200" y2="200" style="stroke:gray;stroke-width:2" stroke-dasharray="5, 5" />
    <line x1="0" y1="0" x2="200" y2="200" style="stroke:blue;stroke-width:2"  mask="url(#myMask)"/>
</svg>

最佳答案

我是这样做的。剪辑中的区域将是可见部分。

 var rectangle = new SvgPolygon();
            var group = new SvgGroup();

            var clip2 = new SvgClipPath
            {
                ID = "Clip2",
                Children =
                {
                    new SvgRectangle()
                    {
                        X = 0,
                        Y = 0,
                        Width = 40,
                        Height = 40
                    }
                }
            };

            group.Children.Add(clip2);
            group.Children.Add(rectangle);
            rectangle.ClipPath =  new Uri("url(#Clip2)", UriKind.Relative);
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">

<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xml="http://www.w3.org/XML/1998/namespace" width="989" height="162" viewBox="0, 0, 100, 100">  
  <g stroke-width="1" font-family="Roboto" font-size="8" font="Roboto" fill-opacity="0" groupName="TopChord" style="stroke:black;">
    <g>
      <clipPath id="Clip2">
        <rect x="0" y="0" width="40" height="40" />
      </clipPath>
      <polygon points="10,20 10,60 90,60 90,20" clip-path="url(#Clip2)" id="0" stroke-width="1" fill-opacity="1" />
    </g>
  </g>
</svg>

关于c# - 如何使用 svg .net 添加蒙版?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73562513/

相关文章:

Android:使用很长的 SVG 文件运行我的应用程序?

c# - 在 mysql/python 或 mysql/.net 中按子字符串对字符串进行分组

c# - 将项目添加到 ImmutableDictionary<TKey, TValue> 内的 ImmutableList<T>

.net - SQLite,将平台特定的 dll 复制到 bin 文件夹

javascript - d3.js 通过 dbclick 事件打开新选项卡

css - Svg 数据图像作为 css 背景?

c# - 没有UAC的Chrome如何更新

java - Byte[] 数组到字符串 C# 到 Java 无需编码

c# - 如何在操作系统检测到 Ctrl-Alt-Del 之前或之后检测到它?

.net - .net 核心项目使用 <DebugType>Full</DebugType> 和 <DebugType>Portable</DebugType> 有什么区别?