如何计算设备像素比

时间:2022-08-27 10:49:54

I would like to know how the -webkit-device-pixel-ratio is calculated.I had already read this: http://www.quirksmode.org/blog/archives/2012/06/devicepixelrati.html.Yet I am unable to understand it clearly. I would also like to know if there is a list of which devices use which pixel ratio.The android website says

我想知道如何计算-webkit-device-pixel-ratio。我已经读过这个:http://www.quirksmode.org/blog/archives/2012/06/devicepixelrati.html。但是我无法清楚地理解它。我还想知道是否有一个列表,哪些设备使用哪个像素比。安卓网站说

The Android Browser and WebView support a CSS media feature that allows you to create styles for specific screen densities—the -webkit-device-pixel-ratio CSS media feature. The value you apply to this feature should be either "0.75", "1", or "1.5", to indicate that the styles are for devices with low density, medium density, or high density screens, respectively.

Android浏览器和WebView支持CSS媒体功能,允许您为特定屏幕密度创建样式 - -webkit-device-pixel-ratio CSS媒体功能。应用于此功能的值应为“0.75”,“1”或“1.5”,以指示样式分别适用于具有低密度,中密度或高密度屏幕的设备。

but I found that we need to use -webkit-device-pixel-ratio=2 to make a web application compatible on 768 x 1280 resolution screen.

但我发现我们需要使用-webkit-device-pixel-ratio = 2来使网络应用程序在768 x 1280分辨率屏幕上兼容。

4 个解决方案

#1


11  

According to this article

根据这篇文章

http://www.html5rocks.com/en/mobile/high-dpi/

The magic number seems to be 150.

神奇的数字似乎是150。

Dividing the physical ppi by the ideal ppi of 150, gives the device pixel ratio.

将物理ppi除以150的理想ppi,得出器件像素比。

E.g. a device with 445ppi would have a dpr of 3 ->> 445 / 150

例如。具有445ppi的设备的dpr为3 - >> 445/150

The simple calculation seems to hold up okay for many items on this list,

对于此列表中的许多项目,简单的计算似乎都没问题,

http://en.wikipedia.org/wiki/List_of_displays_by_pixel_density

#2


1  

you can find the pixel ratio using javascript window.devicePixelRatio

你可以使用javascript window.devicePixelRatio找到像素比率

#3


0  

claculate display metrics and get

claculate显示指标并得到

DisplayMetrics dm = context.getResources().getDisplayMetrics(); int densityDpi = dm.densityDpi

DisplayMetrics dm = context.getResources()。getDisplayMetrics(); int densityDpi = dm.densityDpi

and use dm.xdpi, or dm.ydpi i.e pixcel desity

并使用dm.xdpi或dm.ydpi即pixcel desity

#4


0  

Device Pixel Ratio (DPR) is the relationship between physical hardware-based pixels and Device-Independent Pixels which are an abstraction. The value of the device pixel ratio is not something which can reliably be calculated as it's based on how the device manufacturer intends to map one type of pixel system to the other. To reliably obtain this information, you will need to request it from the device.

设备像素比(DPR)是基于物理硬件的像素和作为抽象的设备无关像素之间的关系。设备像素比的值不能可靠地计算,因为它基于设备制造商打算如何将一种类型的像素系统映射到另一种像素系统。要可靠地获取此信息,您需要从设备请求它。

#1


11  

According to this article

根据这篇文章

http://www.html5rocks.com/en/mobile/high-dpi/

The magic number seems to be 150.

神奇的数字似乎是150。

Dividing the physical ppi by the ideal ppi of 150, gives the device pixel ratio.

将物理ppi除以150的理想ppi,得出器件像素比。

E.g. a device with 445ppi would have a dpr of 3 ->> 445 / 150

例如。具有445ppi的设备的dpr为3 - >> 445/150

The simple calculation seems to hold up okay for many items on this list,

对于此列表中的许多项目,简单的计算似乎都没问题,

http://en.wikipedia.org/wiki/List_of_displays_by_pixel_density

#2


1  

you can find the pixel ratio using javascript window.devicePixelRatio

你可以使用javascript window.devicePixelRatio找到像素比率

#3


0  

claculate display metrics and get

claculate显示指标并得到

DisplayMetrics dm = context.getResources().getDisplayMetrics(); int densityDpi = dm.densityDpi

DisplayMetrics dm = context.getResources()。getDisplayMetrics(); int densityDpi = dm.densityDpi

and use dm.xdpi, or dm.ydpi i.e pixcel desity

并使用dm.xdpi或dm.ydpi即pixcel desity

#4


0  

Device Pixel Ratio (DPR) is the relationship between physical hardware-based pixels and Device-Independent Pixels which are an abstraction. The value of the device pixel ratio is not something which can reliably be calculated as it's based on how the device manufacturer intends to map one type of pixel system to the other. To reliably obtain this information, you will need to request it from the device.

设备像素比(DPR)是基于物理硬件的像素和作为抽象的设备无关像素之间的关系。设备像素比的值不能可靠地计算,因为它基于设备制造商打算如何将一种类型的像素系统映射到另一种像素系统。要可靠地获取此信息,您需要从设备请求它。