首页 > 解决方案 > 如何在 WPF 中设置 SVG 图像的颜色?

问题描述

我们从模型中接收到 SVG 图像路径。这个镜像也用在 web 和 winform 上,所以我们不能使用 XAML。这些只是灰色图像,我们需要能够为这些图像设置任何颜色。我想知道是否可以添加某种仅设置非透明部分颜色的颜色层?

这是我现在所拥有的:

<Window x:Class="CustomBrushesExample.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:svg1="clr-namespace:SVGImage.SVG;assembly=DotNetProjects.SVGImage"
         xmlns:local="clr-namespace:CustomBrushesExample" WindowStartupLocation="CenterScreen"
        Title="SVGImage" Height="540" Width="720" Background="Wheat" ResizeMode="NoResize" Margin="3">
            <svg1:SVGImage 
                x:Name="StartingImage" SizeType="SizeToContent"
                Source="/CustomBrushesExample;component/Images/test_3.svg" 
                Margin="20" 
                RenderTransformOrigin="0.5,0.5" 
                VerticalContentAlignment="Top" 
                HorizontalContentAlignment="Left" 
                HorizontalAlignment="Left" 
                VerticalAlignment="Top"/>
</Window>

SVGImage 是显示 SVG 图像的 .net 团队实现:https ://github.com/dotnetprojects/SVGImage

标签: c#wpfxamlsvg

解决方案


推荐阅读