【问题标题】:How to write scalable SVG without ViewBox parameter?如何在没有 ViewBox 参数的情况下编写可扩展的 SVG?
【发布时间】:2016-01-10 20:00:02
【问题描述】:

我使用的 C# 库不支持 SVG 文件中的 viewBox 参数,但没有它我的图像会被截断,因为它们无法正确缩放,详情如下...

我正在使用 xamarin 表单平台和this nuget 插件(在 XAML 和 C# 中)编写移动应用程序。该插件对 SVG 的支持非常有限,因此我不得不手动更改 svg 文件。生成时,Google+ 图片具有以下第一个标签,但是,当我使用此文件时,我收到以下错误消息:

<svg id="Capa_1" data-name="Capa 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><title>Google_Round</title><

System.Exception:上下文创建的参数无效 在 /Users/builder/data/lanes/2377/73229919/source/maccore/src/CoreGraphics/CGContext.cs:161 中的 CoreGraphics.CGContext.set_Handle(IntPtr 值)[0x00010] 在CoreGraphics.CGContext..ctor(IntPtr句柄,布尔拥有)[0x00006]在/Users/builder/data/lanes/2377/73229919/source/maccore/src/CoreGraphics/CGContext.cs:141 在 CoreGraphics.CGBitmapContext..ctor(IntPtr 数据,nint 宽度,nint 高度,nint bitsPerComponent,nint bytesPerRow,CoreGraphics.CGColorSpace colorSpace,CGImageAlphaInfo bitmapInfo)[0x00000] 在 /Users/builder/data/lanes/2377/73229919/source/ maccore/src/CoreGraphics/CGBitmapContext.cs:62 在 NGraphics.iOS.Custom.ApplePlatform.CreateImageCanvas (大小,双倍比例,布尔透明度)[0x0005c] in :0 在 SVG.Forms.Plugin.iOS.SvgImageRenderer.OnElementChanged (Xamarin.Forms.Platform.iOS.ElementChangedEventArgs`1 e) [0x0010f] 中:0

如果我将第一个标签更改为来自已知工作示例的第一个标签的副本,我有以下 SVG 文件。

<?xml version="1.0"?>
<svg xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" height="300" width="300" version="1.1" fill-opacity="0"> xml:space="preserve">
        <path fill="#54534A" d="M2204.344,4414.691v-122.67h81.643h81.642l-1.237,6.804c-0.619,3.505-1.649,10.515-2.474,15.462l-1.443,8.659
            h-61.438h-61.644v38.141v38.141h54.635h54.635v16.493v16.494h-54.635h-54.635v36.079v36.08h60.613h60.407l1.443,10.515
            c0.825,5.979,2.062,13.401,2.68,16.493l1.237,5.979h-80.818h-80.612V4414.691z"/>
    <!-- Various Strokes omitted -->
    </g>
    </svg>

这为我提供了以下显示的完整 G+ 图标。我认为这是因为我丢失了文件中的viewBox 信息。我还能如何包含此信息以确保我的 svg 适当扩展,而不会导致插件失败?

【问题讨论】:

  • 我怀疑您对第一个文件的问题是因为它没有指定 widthheight。如果将width="512" height="512" 添加到该文件中的&lt;svg&gt; 标记会发生什么情况。这有什么不同吗?
  • @PaulLeBeau 非常感谢 - 已经解决了!如果您发布答案,我会破坏它。

标签: c# css wpf xaml svg


【解决方案1】:

我怀疑您对第一个文件的问题是因为它没有指定 widthheight。如果添加会发生什么

 width="512" height="512"

到该文件中的&lt;svg&gt; 标记。这有什么不同吗?

【讨论】:

    猜你喜欢
    • 2018-09-05
    • 2014-03-03
    • 2010-09-05
    • 2012-08-28
    • 2013-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-08
    相关资源
    最近更新 更多