How to calculate device pixel ratio

后端 未结 6 1421
独厮守ぢ
独厮守ぢ 2020-12-14 01:44

I would like to know how the -webkit-device-pixel-ratio is calculated. I had already read this. Yet I am unable to understand it clearly. I would also like to know if there

相关标签:
6条回答
  • 2020-12-14 02:02

    According to this article

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

    The magic number seems to be 150.

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

    E.g. a device with 445ppi would have a dpr of 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

    0 讨论(0)
  • 2020-12-14 02:07

    you can find the pixel ratio using javascript window.devicePixelRatio

    0 讨论(0)
  • 2020-12-14 02:15

    The problem is that there is no one database with all of (even the most common) devices listed, so looking up the viewport specs for a given device are a case of trying to find the device in any one of several databases.

    These are the databases that I've come across and used, that list device viewports along with their pixel ratios:

    • https://yesviz.com/devices.php (currently the most comprehensive)
    • http://dpi.lv/
    • https://www.mydevice.io/#compare-devices
    • https://viewportsizer.com/devices/
    • http://screensiz.es

    Feel free to add to the list above, as I'm sure there are much more comprehensive databases out there.

    Also remember that resolution / DPR = viewport, so for testing the responsiveness of a site you generally only need one of either DPR or viewport, and the viewport itself is generally better.

    0 讨论(0)
  • 2020-12-14 02:18

    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.

    0 讨论(0)
  • 2020-12-14 02:24

    You can find many of your screen parameters by visiting https://www.mydevice.io/

    0 讨论(0)
  • 2020-12-14 02:29

    claculate display metrics and get

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

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

    0 讨论(0)
提交回复
热议问题