AlgoGames Posted May 5, 2018 Share Posted May 5, 2018 Guys, do you know how to accurately convert dpi to pixels on mobile using java script. I am trying to display Admob banner ads in my HTML5 game which is compiled to Android app using cordova and I am trying to leave some space on the game screen for ads. Though I can leave some approximate space but I am wondering if there is some api available (or even a plugin in cordova) which gives accurate conversion from dpi to pixels. Admob ad sizes are defined in dpi and not in pixels. Quote Link to comment Share on other sites More sharing options...
mattstyles Posted May 9, 2018 Share Posted May 9, 2018 dpi isn't a measure of size, so I'm not really sure what you need to do, but, getting the device's pixel density in a browser environment can be done using `window.devicePixelRatio` in all modern browsers. Does that help? Quote Link to comment Share on other sites More sharing options...
AlgoGames Posted May 10, 2018 Author Share Posted May 10, 2018 15 hours ago, mattstyles said: dpi isn't a measure of size, so I'm not really sure what you need to do, but, getting the device's pixel density in a browser environment can be done using `window.devicePixelRatio` in all modern browsers. Does that help? Not exactly. Since Google specifies ad sizes in dpi, it is already calculating ad sizes for display. I was wondering if there was a quick and accurate way of getting this information in a cordova app. It does not look like a trivial problem though. Quote Link to comment Share on other sites More sharing options...
BobF Posted May 10, 2018 Share Posted May 10, 2018 Matt is correct, DPI is a measure of resolution, not a measure of length or width. An ad may have a DPI of 72 but doesn't tell you anything about its size. Try Googling "calculate size of admob ads". Some of the search results look promising. Quote Link to comment Share on other sites More sharing options...
AlgoGames Posted May 11, 2018 Author Share Posted May 11, 2018 16 hours ago, BobF said: Matt is correct, DPI is a measure of resolution, not a measure of length or width. An ad may have a DPI of 72 but doesn't tell you anything about its size. Try Googling "calculate size of admob ads". Some of the search results look promising. I know. Already googled and planned to continue it once I am done with my latest game which I plan to convert to Android app. Your response is much appreciated. I just thought it would be easy to pick someone's brain here. At the same time I am also wondering how many HTML5 devs are actually releasing their games to Android, iOS stores. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.