Mono 上的 C# 位图类具有无效属性

jn1*_*1kk 2 c# mono openxml .net-3.5

我正在使用NET 3.5 库System.Drawing.Bitmap中的类System.Drawing

代码是这样的:

Bitmap bm = new Bitmap(filename);
Console.WriteLine("bm.width: " + bm.width); // RETURNS 233, RIGHT AMOUNT
Console.WriteLine("bm.HorizontalResolution: " + bm.HorizontalResolution); // RETURNS 0!!
Run Code Online (Sandbox Code Playgroud)

有谁有我可以使用的不同兼容类,或者单声道的任何技巧可以使这项工作正常进行?我需要在 Word 中正确缩放图像的分辨率(我正在生成 .docx 文件)。

Mono JIT compiler version 3.2.8 (Debian 3.2.8+dfsg-4ubuntu1)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
Run Code Online (Sandbox Code Playgroud)

System.Drawing.Image具有相同的行为。

小智 5

看来 System.Drawing.Graphics 在 Linux 环境下返回“正确的”Dpi 信息。

var imgPhoto = System.Drawing.Image.FromFile(imgAbsolutePath); // object with HorizontalResolution and VerticalResolution that return 0 on Linux
var gImage = System.Drawing.Graphics.FromImage(imgPhoto); 
var dpiX = gImage.DpiX;
var dpiY = gImage.DpiY;
Run Code Online (Sandbox Code Playgroud)

至少,这在 .NET Core 2.2 上仍然是一个问题。