【发布时间】:2020-09-12 00:52:15
【问题描述】:
我现在正在使用 UWP 应用程序,我需要从网址转换 SVG 图像。我用新的 Uri 创建了新的 SvgImageSource,但图像渲染不正确。在 SVG 文档中,我有 2 个标记:矩形和文本。矩形正确呈现,但文本无法呈现。有谁知道如何解决这个问题?
C#代码:
public async Task<ImageSource> GetAvatar(string address)
{
using(var client = new HttpClient())
{
var response = await client.GetAsync(address);
string content = await response.Content.ReadAsStringAsync();
if(content.Substring(0, 4).Equals("<svg"))
{
var svg = new SvgImageSource(new Uri(address));
return svg;
}
return new BitmapImage();
}
}
SVG:
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200">
<rect width="100%" height="100%" fill="#FF5722"/>
<text x="50%" y="50%" dy="0.36em" text-anchor="middle" pointer-events="none" fill="#ffffff" font-family="'Helvetica', 'Arial', 'Lucida Grande', 'sans-serif'" font-size="125">
M
</text>
</svg>
【问题讨论】:
-
您从哪里获得示例 SVG?字体类型和大小可能不在您的机器上。 125 字号非常大。
-
内容来自 Rocket.Chat API。当您注册新帐户时,脚本会在 SVG 中为您生成头像