0

I have a bitmap and the reported HorizontalResolution and VerticalResolution properties are both 96. But when I open the same image in Gimp, the reported dpi is 300x300.

Why is there a difference?

Ivan-Mark Debono
  • 15,500
  • 29
  • 132
  • 263
  • What do other applications, like IrfanView or windows properties-details say? 96dpi is a common screen resolution. If you create a bitmap it will default to your screen resolution. You can set the resolution before saving, though. – TaW Jun 20 '16 at 11:17
  • Possible duplicate of [Convert Pixels to Points](http://stackoverflow.com/questions/139655/convert-pixels-to-points) – Thomas Weller Jun 20 '16 at 11:45
  • Not a duplicate as far as I can tell. The link is about [typograhical points](https://en.wikipedia.org/wiki/Point_%28typography%29), not resolution! – TaW Jun 20 '16 at 11:48
  • This question is devoid of important details. But sure, this can happen, the JPEG codec is buggy on Win7 and fumbles dpi. – Hans Passant Jun 20 '16 at 11:55

2 Answers2

1

This a possible way to get different results from the same file:

  Bitmap bmp1 = (Bitmap)Bitmap.FromFile(some300dpiImage);
  Bitmap bmp2 = new Bitmap(bm1);

Now bmp1 will report 300dpi (or to be precise: ppi) as expected.

But bmp2 is a new bitmap, created from the same pixels but with the current screen resolution and it will report whatever your machine's screen resolution is. Mine is 120dpi/ppi.

Note: This has nothing to do with dpi vs ppi - for a discussion about dpi - ppi see here.

TLTR: dpi in the strict sense is only related to printing hardware. There is no reason why image software could report anything but ppi. But ppi are almost always called dpi so we can do the same as call pixels dots and vice versa..

TaW
  • 53,122
  • 8
  • 69
  • 111
0

The Image reports the resolution in PPI. To convert to DPI (as shown in GIMP), use the following formula:

var dpiWidth = image.Width * 72 / image.HorizontalResolution;
var dpiHeight = image.Height * 72 / image.VerticalResolution;
Ivan-Mark Debono
  • 15,500
  • 29
  • 132
  • 263
  • I doubt this is actually your problem nor an answer let alone a solution... Show us how you read the image! There is a subtle way to confuse your programm about the resolution.. - (dpi in the strict sense is only related to printing hardware. There is no reason why gimp would report anything but ppi. They are almost are called dpi. See [here for a discussion](https://en.99designs.de/blog/tips/ppi-vs-dpi-whats-the-difference/) – TaW Jun 20 '16 at 11:31
  • @Taw On checking again, Gimp is reporting ppi. However Gimp reports 300 whilst the image reports 96. – Ivan-Mark Debono Jun 20 '16 at 11:33