使用 JavaScript 的图像 Dpi

Tin*_*nku 5 javascript

我可以使用 javascript 知道图像 dpi (水平和垂直分辨率)吗?

nik*_*s-e -6

我认为 DPI 不是图像的属性。DPI 是打印时使用的测量单位。

无论如何...您可以通过以下方式获取图像的宽度和高度:

var image = new Image();
image.src = "http://cdn.sstatic.net/stackexchange/img/logos/so/so-logo.png";

//show width and height in alert-popup
alert("Width: "+image.width+", Height: "+image.height);
Run Code Online (Sandbox Code Playgroud)

如果不指定宽度和/或高度,img 元素的大小始终与图像本身相同。这就是为什么这应该有效:)