【问题标题】:How to use svg image file in XAML Image component如何在 XAML 图像组件中使用 svg 图像文件
【发布时间】:2021-12-01 03:58:17
【问题描述】:

我正在尝试使用 svg 在 uwp 应用程序上显示插图。我正在使用 svg 创建 BitmapImage 对象,如下所示

m_imageSource = Windows::UI::Xaml::Media::Imaging::BitmapImage(Windows::Foundation::Uri{ GetFilePath() + L"FamilyValueProp\\Assets\\Images\\family_promo.svg"});

并将此来源设置为 Image 组件

<Image x:Name="PromoImage" Source="{x:Bind ViewModel.ImageSource, Mode=OneWay}" />

但这不会渲染图像。图像存在于提供给 BitmapImage 对象的路径中。不知道出了什么问题。有什么帮助吗?

【问题讨论】:

  • @shawan Kendrot 的答案应该有效,您可以检查一下。

标签: xaml uwp winrt-xaml uwp-xaml


【解决方案1】:

如果创建 ImageSource,您将需要使用 SvgImageSource

m_imageSource = new SvgImageSource(new Uri("mySvgImage.svg"));

你也可以直接把svg设置成Image

<Image Source="Assets/mysvg.svg"/>

注意不支持动画

SvgImageSource 支持 SVG 规范中的安全静态模式,但不支持动画或交互

【讨论】:

    猜你喜欢
    • 2019-10-10
    • 1970-01-01
    • 1970-01-01
    • 2012-11-23
    • 1970-01-01
    • 2012-12-12
    • 1970-01-01
    • 1970-01-01
    • 2019-05-24
    相关资源
    最近更新 更多