How to get resolution of an image?

Asked

Viewed 444 times

1

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

  • What image? Give more data, put what you are doing.

  • I have an image on the server where the application is. I need to get this data (resolution) from it.

  • 1

    This you’ve already written, but if you don’t give relevant information about what you’re doing, what you’re using, giving an example of code, what resources you’re using, it’s impossible to answer.

1 answer

3


If it’s height and width, it’s pretty 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 be 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;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.