简体   繁体   English

System.Drawing.Common DrawString 无法在 Linux 中正确呈现文本

[英]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 上的显示方式

它在 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.

相关问题 System.Drawing.Common 不适用于 Windows - System.Drawing.Common not working on Windows .NET Core System.Drawing.Common PrintDocument在Linux上不起作用 - .NET Core System.Drawing.Common PrintDocument doesn't work on Linux System.drawing.common 'gdip' 的类型初始值设定项抛出异常 - System.drawing.common the type initializer for 'gdip' threw an exception 无法在 DLL 的类中加载依赖项 system.drawing.common - Cannot load dependency system.drawing.common in a class in a DLL 为什么无法删除System.Drawing并替换为NuGet包System.Drawing.Common - Why unable to remove System.Drawing and replace with NuGet package System.Drawing.Common 在 AWS Lambda 上使用 System.Drawing.Common NuGet 包时无法加载 DLL“libdl” - Unable to load DLL 'libdl' when using System.Drawing.Common NuGet package on AWS Lambda 如何在使用“.NETFramework,Version=v4.5.2”的项目中安装 System.Drawing.Common? - How do I install System.Drawing.Common in a project that uses '.NETFramework,Version=v4.5.2'? 在 Mac OS X 上使用 System.Drawing.Common 将 BMP 转换为 TIFF - Convert BMP to TIFF using System.Drawing.Common on Mac OS X Xamarin.iOS无法从引用的System.Drawing.Common中识别“位图”类型 - Xamarin.iOS does not recognize the 'Bitmap' type from the referenced System.Drawing.Common .NET System.Drawing.Common 4.5.1 的 NuGet 包包含不正确的程序集版本 - NuGet package for .NET System.Drawing.Common 4.5.1 contains incorrect version of assemblies
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM