【Android】px、dp、sp、ppi、dpi

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/sandalphon4869/article/details/100536401


First, the concept

  • px: pixels (pixels)
  • dp / dip: device independent pixels (device independent pixel)
  • sp: scaled pixels (pixels amplification)
  • ppi: pixels per inch (pixel density, is represented by the number of pixels per inch owned)
  • dpi: dots per inch (dots per inch)

Generally, we can find on a mobile phone network to a certain configuration information can be obtained by resolution (px), size (inch) and ppi.

Here Insert Picture Description

1.px (pixels)

A pixel is generally regarded as a complete image of the sample minimal. Commonly referred to a resolution such as 1280 * 720, it refers to display 1280 * 720 pixels.

2.dp (device independent pixel)

The hardware and related equipment, different devices have different display. In doing the project, in order to fit a wide range of mobile phones on the market resolution recommended dp.

3.sp (enlarged pixel)

SP name is Scale-independent Pixels, a font size , which is consistent with the concept and DP, but also in order to maintain device-independent.

4 inch (Inch)

5.5 inches phone does not refer to the length and width, but rather oblique diagonal 5.5 inches.

5.ppi (image sampling rate)

Pixels Per Inch, pixels (pixel) per inch diagonal have the number.

Ppi calculated as:

Here Insert Picture Description

Calculated with a long number of pixels with a high number of pixels in the diagonal direction (right triangle), and then divided by the number of pixels in the diagonal screen size is a ppi.

Examples of PPI: 4.3 inches with a resolution of 1280 * 720

P P I = ( 128 0 2 + 72 0 2 ) / 4.3 = 341.5359 342 PPI=√(1280^2+720^2)/4.3=341.5359……≈342

note:

ppi only a single value is determined by the resolution and size.
ppi as the effect of the image displayed on the same. The small things ppi display device placed on a large ppi equipment, things will be significantly smaller.

6.dpi (print resolution)

Dots Per Inch, dpi = number of pixels per inch in an image .

Screen density is closely related to the dpi, the greater the density, the more content per inch satisfied points.

Now, he said dpi = ppi, the calculation is also consistent.

Difference is, ppi display commonly used in mobile phone terms, dpi terms commonly used in the printed output.

Second, the conversion

1.px and dp

p x = d p ( d p i / 160 ) px=dp*(dpi/160)

2.dpi=ppi

Example: Configuring simulator
target model for the resolution of 1920 * 1080, ppi is 401, the size is 5.5 inches.
We use dp and sp as a resource unit.

(1) you can specify any simulator dpi

So the resolution only need to simulator is also set to 1920 * 1080, the size is 5.5 inches, dpi = 320.

(2) simulator dpi is a fixed value

And because they can not set the same target model dpi, then we can only adjust the screen resolution size to achieve the same effect on different dpi models.

For example: the simulator is only 320dpi dpi

Provided the original length of the screen a px, width b px, and the new screen resolution ka kb.
a 2 + b 2 5.5 = 401 ( k a ) 2 + ( k b ) 2 5.5 = 320 \ Dfrac {\ sqrt {a ^ 2 + b ^ 2} {5.5} = 401}, \ dfrac {\ sqrt {(ka) ^ 2 + (kb) ^ 2} {5.5} = 320}

k = 320 ÷ 401 = 0.798 k=320\div401=0.798

The new screen length: k a = 0.798 × 1920 = 1532 k b = 0.789 × 1080 = 852 The 0,798 = \ times 1920 = 1532, 0,789 kb = \ times 1080 = 852
but not to.

Why is the coefficient k 2 k^2
k 2 a = 0.638 × 1920 = 1226 k b = 0.638 × 1080 = 689 k^2a=0.638\times 1920=1226,kb=0.638\times 1080=689


Reference:
the Android in px, ppi, dpi, dp, dip, sp analytical concept

Guess you like

Origin blog.csdn.net/sandalphon4869/article/details/100536401