标签: system.drawing.common

.NET 6 System.Drawing.Common 运行时开关

根据https://learn.microsoft.com/en-us/dotnet/core/compatibility/core-libraries/6.0/system-drawing-common-windows-only System.Drawing.Common 不再受非支持Windows 操作系统,除非设置了运行时配置开关。我已经设置了runtimeconfig.template.json并看到了开关:

"runtimeOptions": {
      "configProperties": {
        "System.Drawing.EnableUnixSupport": true
      }
    }
Run Code Online (Sandbox Code Playgroud)

bin/Debug/net6.0 中的文件 .runtimeconfig.json 内

但是,当我在 Linux 盒子中运行该应用程序时,dotnet exec app.dll我仍然得到 PlatformNotSupportedException

system.drawing.common .net-6.0

15
推荐指数
1
解决办法
1万
查看次数

使用 C# 以跨平台方式测量字符串的宽度(以像素为单位)

我有一些现有的 C# 代码,用于System.Drawing.Common测量字符串的近似宽度(以像素为单位):

var text = "abc123 this is some long text my dog's name is fido.";

using (var bitmap = new Bitmap(500, 50))
using (var graphics = Graphics.FromImage(bitmap))
{
    // Size: 9 Points
    using var font = new System.Drawing.Font(familyName: "Times New Roman", emSize: 9f);
    
    var ms = graphics.MeasureString(text, font);
    
    // Output: 'abc123 this is some long text my dog's name is fido.' via System.Drawing: 394.00195 x 22.183594
    Console.WriteLine($"'{text}' via System.Drawing: {ms.Width} x {ms.Height}");
}
Run Code Online (Sandbox Code Playgroud)

升级到 后.NET …

skiasharp imagesharp system.drawing.common .net-6.0

7
推荐指数
1
解决办法
2058
查看次数