- Home /
Screens.dpi different than manufacturer number
Android Screen.dpi value seems off by a few pixels than manufacturer's officially reported dpi... Where is Unity getting this value from?
Answer by soxjke · Dec 19, 2012 at 10:36 PM
Actually, vertical and horizontal dpi on much screens are different values...Unity gets either vert or horiz or average dpi. For much applications it doesn't matter: they differ a little. If you really need PRECISE dpi, you have to hardcode it. For example my GalaxyS smartphone has parameters: Screen res: 480x800, 4inch disp. Manufacturer says 233 dpi. Looks like its average : sqrt(480*480 + 800 * 800)=233,3... Unity gives 235 dpi. My iPhone 4S : Screen res 640x960, 3.5inch disp. Manufacturer says 330, calculation gives: sort(960*960 + 640*640) = 329.65.. Unity gives 320 dpi. So, mistake is ignorable.
That's the thing, how does Unity get 236 from 233,3? How is unity calculating the dpi?
I think, no calculation is performed. It can take either vertical or horizontal for Android.. check (This is Java code, not Unity script!):
Display$$anonymous$$etrics dm = new Display$$anonymous$$etrics();
getWindow$$anonymous$$anager().getDefaultDisplay().get$$anonymous$$etrics(dm);
// these will return the actual dpi horizontally and vertically
float xDpi = dm.xdpi;
float yDpi = dm.ydpi;
I am sure, u will get one of this values in Unity. Try, if u want, but i still don't understand, why do u need so precise dpi calculation. $$anonymous$$uch android apps use Display$$anonymous$$etrics.densityDpi * 160 which results in 80, 160, 240, 320, 480 dpi - which gives exactly greater mistake. $$anonymous$$aybe unity does (xdpi +ydpi) / 2. Still can't believe such precision is important.
Your answer
Follow this Question
Related Questions
Resolution independence 0 Answers
How do I access CoreMotion and the Android equivalent? 0 Answers
C++ windows DLL and Android? 1 Answer
I'm looking for help with enemy AI scripting and animations. 1 Answer
iOS and Android Publishing 2 Answers