Understanding the Relationship Between DPI, Screen Resolution, and Image Pixel Density in Android Development

Summit Kumar
4 min readMar 15, 2023

--

When designing mobile applications, it is essential to consider the various devices that the application will run on. One crucial aspect to consider is the pixel density of the device’s screen. The pixel density of a device’s screen affects how images and graphics appear on the device. In Android development, the pixel density of a device’s screen is referred to as DPI (dots per inch). Understanding the relationship between DPI, screen resolution, and image pixel density is essential to ensure that images and graphics appear correctly on all devices.

Understand DPI, pixels and images for android
DPI illustration

DPI and Screen Resolution

DPI refers to the number of pixels that are present per inch on a device’s screen. A higher DPI means that there are more pixels per inch, resulting in higher image quality and sharper graphics. In contrast, a lower DPI means that there are fewer pixels per inch, resulting in lower image quality and less sharp graphics.

Screen resolution, on the other hand, refers to the number of pixels that a device’s screen can display. It is usually represented by the number of pixels along the horizontal and vertical axes. For example, a device with a resolution of 720x1280 means that the screen can display 720 pixels along the horizontal axis and 1280 pixels along the vertical axis.

Pixel Density and Image Size

In Android development, pixel density is used to determine the size of images and graphics on a device’s screen. The pixel density is classified into different categories, namely LDPI (low-density), MDPI (medium-density), HDPI (high-density), XHDPI (extra-high-density), XXHDPI (extra-extra-high-density), and XXXHDPI (extra-extra-extra-high-density).

Each of these categories represents a different range of pixel densities, and the pixel density determines the size of images and graphics on the screen. To ensure that images and graphics appear correctly on all devices, it is crucial to create images and graphics of different sizes for each category.

Calculating Pixel Density

To determine the pixel density of a device’s screen, you need to know its screen resolution and physical screen size. The pixel density is calculated by dividing the number of pixels on the screen by the screen size in inches. For example, a device with a screen resolution of 720x1280 and a screen size of 5 inches would have a pixel density of 294 DPI (1280 pixels / 5 inches).

Dots per inch (dpi) is a measure of the resolution of an output device, such as a printer or a screen. DPI represents the number of dots or pixels that can be displayed or printed per inch of the device. The higher the DPI, the more detailed and higher quality the output will be.

In the case of screens, DPI is calculated based on the physical size of the screen and the number of pixels it contains. The formula for calculating DPI is as follows:

DPI = (square root of (horizontal pixels² + vertical pixels²)) / diagonal screen size in inches

For example, if a screen has a resolution of 1920 x 1080 pixels and a diagonal size of 15.6 inches, the DPI can be calculated as follows:

DPI = (square root of (1920² + 1080²)) / 15.6 DPI = 141.2

Creating Images for Different Pixel Densities

To ensure that images and graphics appear correctly on all devices, you need to create images of different sizes for each pixel density category. The size of the image is determined by multiplying the scale factor (the ratio of the pixel density of the device to the base pixel density of 160 DPI) by the image’s original size.

Here are the formulas to calculate the different DPI densities:

  1. LDPI (low-density) devices: 120 dpi Resolution: 240 x 320 pixels Formula: dpi / 160 = scale factor 120 / 160 = 0.75
  2. MDPI (medium-density) devices: 160 dpi Resolution: 320 x 480 pixels Formula: dpi / 160 = scale factor 160 / 160 = 1.0
  3. HDPI (high-density) devices: 240 dpi Resolution: 480 x 800 pixels Formula: dpi / 160 = scale factor 240 / 160 = 1.5
  4. XHDPI (extra-high-density) devices: 320 dpi Resolution: 720 x 128
  5. XXHDPI (extra-extra-high-density) devices: 480 dpi Resolution: 1080 x 1920 pixels Formula: dpi / 160 = scale factor 480 / 160 = 3.0
  6. XXXHDPI (extra-extra-extra-high-density) devices: 640 dpi Resolution: 1440 x 2560 pixels Formula: dpi / 160 = scale factor 640 / 160 = 4.0

For example, if you have an image with an original size of 100 x 100 pixels and you want to create images for all pixel density categories, you would use the following formulas:

  1. LDPI (low-density) devices: Scale factor = 0.75 Image size = 100 x 0.75 = 75 x 75 pixels
  2. MDPI (medium-density) devices: Scale factor = 1.0 Image size = 100 x 1.0 = 100 x 100 pixels
  3. HDPI (high-density) devices: Scale factor = 1.5 Image size = 100 x 1.5 = 150 x 150 pixels
  4. XHDPI (extra-high-density) devices: Scale factor = 2.0 Image size = 100 x 2.0 = 200 x 200 pixels
  5. XXHDPI (extra-extra-high-density) devices: Scale factor = 3.0 Image size = 100 x 3.0 = 300 x 300 pixels
  6. XXXHDPI (extra-extra-extra-high-density) devices: Scale factor = 4.0 Image size = 100 x 4.0 = 400 x 400 pixels

In conclusion, understanding the relationship between DPI, screen resolution, and image pixel density is crucial for creating mobile applications that appear correctly on all devices. By creating images of different sizes for each pixel density category, you can ensure that your images and graphics appear sharp and clear, regardless of the device they are viewed on. With this knowledge, you can create stunning mobile applications that look great on any device.

--

--

Summit Kumar

Tech-savvy BTech IT professional with a passion for latest technologies. Always seeking new challenges & opportunities to expand my knowledge. #KeepLearning #IT