Convert PX to DP

First of all, I’m a mobile developer and I’m risking the development of a layout for my app, right from the start I found the following problem, Photoshop uses PX as a unit of measure for the forms and in development the app uses DP, I know how the conversion works From PX to PD

dp = px * (160 / dpi)

However when I apply a formula and use the values ​​in the programming the layout breaks, I would like to know if there is a PSD file configuration, such as height, width, pixel density where I can use as the basis to mockup my app so Make it easy to carry these measures for mobile and tablets ?

Answer

Photoshop uses PX as a unit of measure for the forms and in development the app uses DP, I know how the conversion works From PX to DP

The conversion will depend on how the original design in Photoshop was constructed. Android’s dp units are density independent pixels. 1dp might render as 1 screen pixel, or 2, or 3, or 4, or some other value, depending on the device and Android settings.

Here’s a list of the common conversions:

  • 1 dp = 1 pixel, or 1×, for mdpi displays (~160PPI).
  • 1 dp = 1.5 pixels, or 1.5×, for hdpi displays (~240PPI).
  • 1 dp = 2 pixels, or 2×, for xhdpi displays (~320PPI).
  • 1 dp = 3 pixels, or 3×, for xxhdpi displays (~480PPI).
  • 1 dp = 4 pixels, or 4×, for xxxhdpi displays (~640PPI).

So, the big question is which density do you want to build your mockups in? You can choose any of the above densities. Your choice will dictate the conversion, and other factors.

My preference is to design at 1×, a scale where 1 dp = 1 px = 1 CSS px = 1 iOS point. That will mean your mockups are lower resolution than the device itself, but it means the conversion requires no change to the value.

When you’re done, Photoshop has a few ways to export assets for the various densities. Export As and Generator can build the other scales, or you can use Save for Web and slices (like I do).

Here’s Photoshop’s Export As window, with the exporting set up for 1×, 2× and 3× densities (for iOS, in this case).

Photoshop’s Export As

Attribution
Source : Link , Question Author : 1fabiopereira , Answer Author : Marc Edwards

Leave a Comment