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.
How do dp, dip, dpi, ppi, pixels and inches relate?
You should (almost) always use flexible sizing units, like dp
, which is Density-Independent Pixels, because 300px
on one device is not necessarily the same amount of screen real estate as 300px
on another. The biggest practical implication is that your layout would look significantly different on devices with a different density than the one your design targeted.
dp
ordip
means Density-independent Pixelsdpi
orppi
means Dots (or Pixels) Per Inchinch
is a physical measurement connected to actual screen sizepx
means Pixels — a pixel fills an arbitrary amount of screen area depending on density.
For example, on a 160dpi
screen, 1dp == 1px == 1/160in
, but on a 240dpi
screen, 1dp == 1.5px
. So no, 1dp != 1px
. There is exactly one case when 1dp == 1px
, and that's on a 160dpi
screen. Physical measurement units like inches should never be part of your design—that is, unless you're making a ruler.
A simple formula for determining how many pixels 1dp
works out to is px = dp * (dpi / 160)
.
How resolution , dpi ,pixel are related with each other
Check out the Supporting Multiple Screen Sizes page of the developer docs, which contains the definitions you are looking for. In short:
- Pixels are the smallest unit you can use with any screen. One pixel is one dot on the screen.
- Resolution is the actual number of pixels in a screen. This number isn't as useful as you would think, because a 4" phone can have the same (or even a higher) resolution as a 10" tablet.
- dpi stands for dots-per-inch. It is the number of pixels per inch in a given screen. This is how Android determines what density bucket (low, high, etc) the device falls in.
- dp (aka dip) stands for density-independent pixel. This is what you should use for most of your layouts. This unit scales with the device's screen density.
When you make a graphic asset for an Android application, you typically take the following steps:
- Determine which screen densities you will support.
- Create your graphic at the highest resolution you will support
- Export the graphic at the lower resolutions, and place them in the appropriate drawable resource folder for that density.
For example, an image that is 96x96 pixels on a extra high-density device should be 36x36 on a low density device, 48x48 on a medium-density device, and 72x72 on a high-density device.
set images for multiple devices which has different ppi pixels
The dp pixels are density independent, not proportion independent. The difference in proportion of height to width between the two devices is the issue you are having, not an occurrence of non-standard dp. The only proper solution is to adjust the weight based on difference in proportion.
If density independent pixels were dependent on the pixels per inch, a density dependent unit, then they would also be density dependent.
PPI PIXEL DENSITY new confuse
As far as marketing materials and tech-sheets are concerned (which I assume is what you're looking at) then they are the same.
PPI = Pixels per inch. A measure of how many pixels lie along a line parallel or perpendicular to the display (i.e. not diagonally).
DPI = Dots per inch. A term used in printing (where are images are made of dots rather than pixels) but carried over to screen terminology.
PPI is the preferred term but they are used interchangeably.
The Android OS supports arbitrary resolutions (note that "resolution" really refers to the DPI of a display rather than the display area's pixel dimensions), so if a display is 285dpi it doesn't necessarily mean that the system (or the applications running on it) draw a 285px-long line and expect it to be 1 inch in real-life, there will be variations. 285dpi is close enough to Android's "HDPI" mode of 240dpi.
You can read more here: How do I convert ppi into dpi for Android images?
Related Topics
Add "View More" at the End of Textview After 3 Lines
Stopping & Starting Music on Incoming Calls
How to Force the Action Bar to Be at the Bottom in Ics
Intent.Resolveactivity Returns Null in API 30
Current Month Facebook Friends Birthdays in Android
Bypass Android Usb Host Permission Confirmation Dialog
Opening Android Settings Programmatically
Android - Cannot Capture Backspace/Delete Press in Soft. Keyboard
Register Application Class in Manifest
Dynamic Listview Adding "Load More Items" at the End of Scroll
Android: Wrap_Content Is Not Working with Listview
Googlesignatureverifier Signature Not Valid Message (Google Play Services 9.0.0)
Androidstudio Cannot Find Layout
Android: Share Plain Text Using Intent (To All Messaging Apps)
Android Studio: How to Attach Android Sdk Sources
How to Detect Whether the Android Phone in Silent Mode Programmatically