dcgames

Convert dpi to pixels in HTML5 games

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.