How do I convert ppi into dpi for Android images?

Dp are Density independant pixels and are used to generalise the number of pixels a screen has. These are generalised figures taken from http://developer.android.com/guide/practices/screens_support.html

  • xlarge screens are at least 960dp x 720dp
  • large screens are at least 640dp x 480dp
  • normal screens are at least 470dp x 320dp
  • small screens are at least 426dp x 320dp

Generalised Dpi values for screens:

  • ldpi Resources for low-density (ldpi) screens (~120dpi)
  • mdpi Resources for medium-density (mdpi) screens (~160dpi). (This is the baseline density.)
  • hdpi Resources for high-density (hdpi) screens (~240dpi).
  • xhdpi Resources for extra high-density (xhdpi) screens (~320dpi).

Therefore generalised size of your resources (assuming they are full screen):

  • ldpi
    • Vertical = 426 * 120 / 160 = 319.5px
    • Horizontal = 320 * 120 / 160 = 240px
  • mdpi
    • Vertical = 470 * 160 / 160 = 470px
    • Horizontal = 320 * 160 / 160 = 320px
  • hdpi
    • Vertical = 640 * 240 / 160 = 960px
    • Horizontal = 480 * 240 / 160 = 720px

Edit – adding xhdpi as they are becoming more popular

  • xhdpi
    • Vertical = 960 * 320 / 160 = 1920px
    • Horizontal = 720 * 320 / 160 = 1440px

These values should be suitable for most xhdpi screens such as TVs and the Nexus 4, including the Nexus 10 (assuming they don’t create a new category for this as it is 25k x 16k, don’t know as I haven’t got hands on one yet).

/Edit


If you use these sizes your images will look great on any screen. Be sure to define sizes in code in dp however, Android will handle the conversion described above on its own.

Leave a Comment