Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
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)
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:
- Reading Image Headers to Get Width and Height
- http://en.wikipedia.org/wiki/Image_quality