Reputation: 5102
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
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