Reputation: 16290
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?
Upvotes: 0
Views: 751
Reputation: 54433
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..
Upvotes: 1
Reputation: 16290
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;
Upvotes: 0