18

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

Avinash
  • 3,231
  • 10
  • 36
  • 46
  • see:http://stackoverflow.com/questions/2207187/how-can-i-get-the-resolution-of-an-image-jpeg-gif-png-jpg – lindexi May 16 '17 at 05:07

2 Answers2

26

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;
Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
Benny
  • 8,547
  • 9
  • 60
  • 93
  • The property comment says that that's _pixels_ per Inch, though... not dots per inch. Not sure if there's a difference... – Nyerguds Jan 09 '18 at 15:28
1

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");
        }
    }
}
JHBonarius
  • 10,824
  • 3
  • 22
  • 41
garyj
  • 1,302
  • 2
  • 13
  • 22