javascript 如何检查图像质量/分辨率/dpi/ppi?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13560017/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 19:09:28  来源:igfitidea点击:

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

javascriptjqueryimageresolutionimage-size

提问by RGA

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

我想检查所选输入图像文件的当前质量(分辨率/dpi/ppi)

my control is image uploader jquery plugin.

我的控件是图像上传器 jquery 插件。

How can i get the quality of selected file?

如何获得所选文件的质量?

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

(我需要选择的图像文件的分辨率而不是屏幕分辨率)

采纳答案by Tom Sarduy

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.

答案是在 C# 中而不是 Javascript,在 JS 中没有办法做到这一点,这不是原始问题中的要求。

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.

这是您认为“高质量”图像的很大依赖(BTW 读起来不错)。但无论如何,品质因数并不直接存储在 JPEG 文件中,因此您无法直接从文件中读取。

Most of these factors involve complex imaging algorithms. But do not be disappointed, you can read some properties using the PropertyItemsproperty 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:

大多数这些因素涉及复杂的成像算法。但是不要失望,您可以使用PropertyItemsImage 类上的属性读取一些属性,并根据大小和 dpi 或 ppi 进行一些计算以了解图像的质量。这是一个简单的例子:

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)

这也将有所帮助:如何获得图像的分辨率?(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?

如果您想在上传前检查图像质量(如您在评论中所说),这是一个很大的问题。获取您想要的数字的唯一内置方法是创建一个新实例(并解码整个图像)——这将是非常低效的。但是……嘿!这是一个起点:如何在不加载图像的情况下可靠地获取 .NET 中的图像尺寸?

Further reading:

进一步阅读: