gpt4 book ai didi

c# - 如何在没有 ViewBox 参数的情况下编写可缩放的 SVG?

转载 作者:行者123 更新时间:2023-11-28 16:35:04 24 4
gpt4 key购买 nike

我使用的 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: Invalid parameters to context creation at CoreGraphics.CGContext.set_Handle (IntPtr value) [0x00010] in /Users/builder/data/lanes/2377/73229919/source/maccore/src/CoreGraphics/CGContext.cs:161 at CoreGraphics.CGContext..ctor (IntPtr handle, Boolean owns) [0x00006] in /Users/builder/data/lanes/2377/73229919/source/maccore/src/CoreGraphics/CGContext.cs:141 at CoreGraphics.CGBitmapContext..ctor (IntPtr data, nint width, nint height, nint bitsPerComponent, nint bytesPerRow, CoreGraphics.CGColorSpace colorSpace, CGImageAlphaInfo bitmapInfo) [0x00000] in /Users/builder/data/lanes/2377/73229919/source/maccore/src/CoreGraphics/CGBitmapContext.cs:62 at NGraphics.iOS.Custom.ApplePlatform.CreateImageCanvas (Size size, Double scale, Boolean transparency) [0x0005c] in :0 at SVG.Forms.Plugin.iOS.SvgImageRenderer.OnElementChanged (Xamarin.Forms.Platform.iOS.ElementChangedEventArgs`1 e) [0x0010f] in :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 适当缩放,而不会导致插件失败? Icon Comparison

最佳答案

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

 width="512" height="512"

<svg>该文件中的标记。这有什么不同吗?

关于c# - 如何在没有 ViewBox 参数的情况下编写可缩放的 SVG?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34696804/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com