Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
45
rated 0 times [  49] [ 4]  / answers: 1 / hits: 19734  / 12 Years ago, mon, november 26, 2012, 12:00:00

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)


More From » jquery

 Answers
33

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:



[#81799] Saturday, November 24, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
frankiefredyr

Total Points: 555
Total Questions: 108
Total Answers: 94

Location: Egypt
Member since Tue, May 3, 2022
2 Years ago
;