How to get resolution of an image?

1

How to get resolution from an image? I have a web application and I need to get this data from an image on localhost.

    
asked by anonymous 09.04.2015 / 19:17

1 answer

3

If it's height and width, it's fairly simple:

string path = @"C:\caminho\qualquer\minha_imagem.jpg";
var img = Image.FromFile(path);
// img.Width é a largura
// img.Height é a altura

Now, if you want the pixels per inch (semantically closer to an image resolution), it would look something like:

string path = @"C:\caminho\qualquer\minha_imagem.jpg";
var img = Image.FromFile(path);
var graf = Graphics.FromImage(img);
var resolucao = (bmp.Width / bmp.HorizontalResolution) * graf.DpiX;
    
09.04.2015 / 23:03