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
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
you can find the pixel ratio using javascript window.devicePixelRatio
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:
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.
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.
You can find many of your screen parameters by visiting https://www.mydevice.io/
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