Bug 33310 - For some images HorizontalResolution and VerticalResolution erroneusly returns 0
Summary: For some images HorizontalResolution and VerticalResolution erroneusly returns 0
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: libgdiplus ()
Version: 3.12.0
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2015-08-22 06:57 UTC by Anonymous
Modified: 2017-01-11 07:39 UTC (History)
3 users (show)

Is this bug a regression?: ---
Last known good build:

Example file for the error (1.27 MB, image/jpeg)
2015-08-22 06:57 UTC, Anonymous
The program to verify the problem (1.38 KB, text/plain)
2015-08-22 07:00 UTC, Anonymous

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report for Bug 33310 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:

Description Anonymous 2015-08-22 06:57:55 UTC
Created attachment 12609 [details]
Example file for the error

Bitmap.HorizontalResolution and Bitmap.VerticalResolution return 0 instead of the valid values for some files. The root cause of the behavious is in libgdiplus.
Error was seen observed on CentOS 7.0 with latest mono from the official repository ( http://download.mono-project.com/repo/centos/)

ggergely@icarus:~/tmp/sandbox $ rpm -qa mono* libgdi*
ggergely@icarus:~/tmp/sandbox $

Because I cannot add multipl attachments, and the picture is a must have, I copy in the program which can verify the error:
using System;
using System.Drawing;
using System.IO;
using System.Linq;

namespace sandbox {
    class Program {
        private const string usage = @"usage:

program <dir1> [<dir2> ... <dirN>]

        static void Main(string[] args) {
            if (args.Length < 1) {

            foreach (var dir in args) {
                if (!Directory.Exists(dir)) {
                    Console.Error.WriteLine("Skipping non-directory element: {0}", dir);

                foreach (var path in Directory.EnumerateFiles(dir, "*.jpg", SearchOption.TopDirectoryOnly)
                                .Union(Directory.EnumerateFiles(dir, "*.jpeg", SearchOption.TopDirectoryOnly))) {

                    // Format is automatically detected though can be changed.
                    using (var inStream = File.OpenRead(path)) {
                        Console.WriteLine("Processing file {0}...", path);
                        var image = new Bitmap(inStream);
                        Console.WriteLine("DEBUG: xres: {0}, yres: {1}", image.HorizontalResolution, image.VerticalResolution);
                        Console.WriteLine("It should not be 0, 0!"); // for the attached file it is 180, 180
Comment 1 Anonymous 2015-08-22 07:00:26 UTC
Created attachment 12610 [details]
The program to verify the problem

Added attachment with the program code.
Compile and start with the directory containg the attached image file as an argument.
Comment 2 Carles 2016-06-16 15:09:14 UTC
Hi, I would like to support this error.

I've noticed it too.

What I did was to use the procedure DrawToBitmap() in order to create that bitmap, and no matter if the bitmap is saved to a file and then loaded or used directly from the Bitmap object, the Resolutions are 0.
Comment 3 Carles 2016-06-16 15:10:30 UTC
By the way, this was noticed in Linux.
Comment 4 raztus 2017-01-11 00:14:05 UTC
On Ubuntu 16.10 with Mono Super simple program to duplicate the issue:

using System;

namespace SystemBitmap
	class MainClass
		public static void Main(string[] args)
			using (System.Drawing.Bitmap bm = new System.Drawing.Bitmap(40, 40))
				Console.WriteLine("bm hr: " + bm.HorizontalResolution);
				Console.WriteLine("bm vr: " + bm.VerticalResolution);

This same program on my Windows 7 desktop prints the correct DPI each time (96 by default, but I also increased the Windows DPI and the Horizontal and Vertical Resolutions were accurately adjusted.)
Comment 5 Carles 2017-01-11 07:39:56 UTC
I've noticed it too. I reported it some months ago but I was ignored.