How to Get DPI of Image in C#

Viewed 20408

how can i get dpi of an image using asp.net c#

2 Answers

How about Image.HorizontalResolution and Image.VerticalResolution? Like this:

System.Drawing.Image image = System.Drawing.Image.FromFile("TestImage.bmp");
var dpiX = image.HorizontalResolution;
var dpiY = image.VerticalResolution;

The answer is stated in this post, which sources it's code from here:

using System;
using System.Drawing;

namespace BitmapDpi
{
    class Program
    {
        static void Main(string[] args)
        {
            Bitmap bmp = new Bitmap("winter.jpg");
            Console.WriteLine("Image resolution: " + bmp.HorizontalResolution + "DPI");
        }
    }
}
Related