How to check image quality/resolution/dpi/ppi? [cl

2020-03-18 13:04发布

i want to check selected input image file's current quality (Resolution/dpi/ppi).

my control is image uploader jquery plugin.

How can i get the quality of selected file?

(i need selected image file's resolution not screen resolution)

1条回答
再贱就再见
2楼-- · 2020-03-18 13:25

Note:

The answer is in C# not Javascript, there is no way to do this in JS and that was not a requirement in the original question.

About your original question

This is a big dependency of what you consider a "high quality" Image (nice reading BTW). But anyway the quality factor is not stored directly in the JPEG file, so you cannot read directly from the file.

Most of these factors involve complex imaging algorithms. But do not be disappointed, you can read some properties using the PropertyItems property on the Image class and make some calculations to get an idea of the quality of the image based on size and dpi or ppi. This is a simple example:

Bitmap bmp = new Bitmap("winter.jpg");
Console.WriteLine("Image resolution: " + bmp.HorizontalResolution + " DPI");
Console.WriteLine("Image resolution: " + bmp.VerticalResolution + " DPI");
Console.WriteLine("Image Width: " + bmp.Width);
Console.WriteLine("Image Height: " + bmp.Height);

This will help too: How can I get the resolution of an image? (JPEG, GIF, PNG, JPG)

"But I want to check selected files image quality before uploading"

If you want to check the image quality before upload (as you said in comments), that's a big plus to the question. The only built-in method to get the numbers you're after is by creating a new instance (and decoding the entire image) - which is going to be highly inefficient. But... hey! here is a start point: How do I reliably get an image dimensions in .NET without loading the image?

Further reading:

查看更多
登录 后发表回答