How do I convert to DIP?
Asked Answered
M

1

5

What is the formula for converting regular pixels to DIP?

Assuming I have a photoshop document with a design in it that was intended for the Galaxy Tab (for example) which is 600x1024 actual pixels.
What is the ratio between those and the DIP? I'm unclear on how Android translates this.

I want to use DIP (rather than pixels) so that it scales to look "ok" on other devices, but my primary concern is to get it pixel perfect in this resolution and my aim is to measure the position of an element in photoshop and then get an exact translation as to what the DIP needs to be for it to lay out identically on the Tab.

Monopolize answered 7/6, 2011 at 17:10 Comment(1)
DIP is just a fancy way of saying "multiply your DIP value with the system's dots-per-inch/DPI value to get a device pixel location". Android defaults to 160dpi I believe, Windows desktops to 72dpi, and WPF to 96 dpi.Slouch
A
11

Their formula is somewhere in the docs:

 truePixels = DIPs * (device DPI / 160) 

Ah, there it is:

The density-independent pixel is equivalent to one physical pixel on a 160 dpi screen, which is the baseline density assumed by the system for a "medium" density screen. At runtime, the system transparently handles any scaling of the dp units, as necessary, based on the actual density of the screen in use. The conversion of dp units to screen pixels is simple: px = dp * (dpi / 160). For example, on a 240 dpi screen, 1 dp equals 1.5 physical pixels. You should always use dp units when defining your application's UI, to ensure proper display of your UI on screens with different densities.

Taken from here.

Abominable answered 7/6, 2011 at 17:16 Comment(3)
I see... so where do I find out what the screen density of the Tab is?Monopolize
Sometimes Wikipedia has a good answer ;): en.wikipedia.org/wiki/List_of_displays_by_pixel_densityAbominable
wow.... that is very useful... but 171 (and with an asterisk no less)... how arbitrary is THAT?! :)Monopolize

© 2022 - 2024 — McMap. All rights reserved.