[英]System.Drawing.Common DrawString not rendering text properly in Linux
So I'm not sure what the issue is and have exhausted just about every option I can think of.所以我不确定问题是什么,并且已经用尽了我能想到的所有选择。 I am targeting dotnet core 3.0 on Ubuntu 18.04 LTS.我的目标是 Ubuntu 18.04 LTS 上的 dotnet core 3.0。 On a windows environment it works fine but in this Ubuntu environment text just does not render the way it is support to and comes out looking something like this在 windows 环境中,它可以正常工作,但在此 Ubuntu 环境中,文本并没有呈现它所支持的方式,并且看起来像这样
How it is supposed to be displayed它应该如何显示
How it is displaying on Ubuntu它在 Ubuntu 上的显示方式
I am using the font Arial and I have the MS TrueType Fonts package installed, I've tried Font families native to Ubuntu and still the same thing.我正在使用 Arial 字体,并且我安装了 MS TrueType Fonts package,我已经尝试过 Ubuntu 原生的字体系列,但还是一样。
I experienced the same issue on Fedora 34.我在 Fedora 34 上遇到了同样的问题。
I used this example file to reproduce the problem:我使用这个示例文件重现了这个问题:
using System.Drawing;
Bitmap bmp = new Bitmap(200, 100);
using var gfx = Graphics.FromImage(bmp);
gfx.Clear(Color.Navy);
Font fnt = new Font("Arial", 18);
gfx.DrawString("test123", fnt, Brushes.Yellow, 10, 10);
bmp.Save("test.bmp");
(Note that the code above compiles and runs with .NET 5 and C# 9.0 since it supports top-level statements, https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/tutorials/top-level-statements .) (请注意,上面的代码使用 .NET 5 和 C# 9.0 编译和运行,因为它支持顶级语句Z5E056C500A1C4B6A7110B50D807BADEdot5Z/ctop -microsoft/levels -声明。)
However, the result looked like this:但是,结果如下所示:
What I did to fix this, was to run the following terminal command:我为解决这个问题所做的是运行以下终端命令:
$ dotnet add package system.drawing.common
After that, re-building and running the program yields this image instead:之后,重新构建并运行程序会生成此图像:
With this change, my .csproj
file now looks like this:通过此更改,我的.csproj
文件现在如下所示:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="system.drawing.common" Version="5.0.2" />
</ItemGroup>
</Project>
Just for reference;仅供参考; the reason I stumbled upon this problem was when I tried to use ScottPlot, and I filed this bug about it: https://github.com/ScottPlot/ScottPlot/issues/1079我偶然发现这个问题的原因是当我尝试使用 ScottPlot 时,我提交了这个错误: https://github.com/ScottPlot/ScottPlot/issues/1079
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.