jn1kk
jn1kk

Reputation: 5102

C# Bitmap Class on Mono Has Invalid Properties

I am using System.Drawing.Bitmap class from System.Drawing library using NET 3.5.

Code is this:

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

Does anyone have a different compatible class I could use, or any tricks for mono to make this work? I need the resolution to scale images properly in Word (I'm generating .docx files).

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

System.Drawing.Image has the same behavior.

Upvotes: 2

Views: 788

Answers (1)

Michał
Michał

Reputation: 106

It seems that System.Drawing.Graphics returns "proper" Dpi information on Linux environment.

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;

At least, this is still a problem on .NET Core 2.2.

Upvotes: 5

Related Questions