如何量化密度影响图像资源选择和缩放? [英] How does quantized density affect image resource selection and scaling?

查看:99
本文介绍了如何量化密度影响图像资源选择和缩放?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每个Android设备都有一个物理像素密度和量化密度。 源头的状态下,将量化密度是用于确定如何所述一个绘制dpi的图像被选择和扩展在运行时。

Each Android device has a physical pixel density and a 'quantized density'. Sources state that the quantized density is the one used to determine how drawable-dpi images are selected and scaled at runtime.

问:precisely如何这些图像(1)选择和(2)按比例

Question: precisely how are these images (1) selected and (2) scaled?

例如,放入绘制-xhdpi桶一个64×64的图像被缩小到什么尺寸?

For example, a 64x64 image placed into the drawable-xhdpi bucket gets scaled to what size?

推荐答案

有关问题的比例部分,首先获得量化密度的设备运行

For the scaling part of the question, first get the quantized density for the device by running

adb shell getprop ro.sf.lcd_density

和调用这个量化密度为设备。一般这种量化的密度不同于设备的物理密度,但如果在物理密度完全落的dpi的桶的边界之一,则它可以是相同的。而物理密度描述了现实世界的测量,量化的密度是由设备制造商设置,并且通常选择为下列值之一:

and call this the quantized density for the device. In general this quantized density differs from the physical density of the device but it can be the same if the physical density falls perfectly as one of the dpi 'bucket' boundaries. Whereas the physical density describes a real-world measurement, the quantized density is set by the device manufacturer, and is usually chosen to be one of the following values:

  • 160
  • 240
  • 320
  • 480

量化密度控制我所说的图像缩放系数(ISF)的设备。其计算公式如下:

Quantized density controls what I will call the Image Scaling Factor (ISF) for the device. The formula is as follows:

ISF = ro.sf.lcd_density / 160

该ISF是在Android的资源装载/布局管理器从文件中读取的资源的位图,并将其呈现在屏幕上(我不知道,如果缩放发生在加载时或渲染所使用的比例因子-时间)。上的Nexus 6装置中,ISF是3.5,因为该量化密度设定为560(和560/160个= 3.5)。可以肯定,在运行时呈现的尺寸也可绘制桶包含有问题的文件的功能。例如,在Nexus的6:

The ISF is the scale factor that is used when Android's resource-loading/layout-manager reads a resource bitmap from a file and renders it to the screen (I don't know if the scaling happens at load-time or render-time). On the Nexus 6 device, the ISF is 3.5 because the quantized density was set to be 560 (and 560 / 160 = 3.5). To be sure, the rendered size at runtime is also a function of the drawable bucket that contains the file in question. For example, on the Nexus 6:

  • 64像素的图像在MDPI文件夹呈现为224像素(因为3.5 * 64 / 1.0 = 224)
  • 64像素的图像在华电国际文件夹呈现为149像素(因为3.5 * 64 / 1.5 = 149)
  • 64像素的图像在xhdpi文件夹呈现为112像素(因为3.5 * 64 / 2.0 = 112)
  • 64像素的图像中xxhdpi文件夹呈现为75像素(因为3.5 * 64 / 3.0 = 75)
  • 64像素的图像中xxxhdpi文件夹呈现为56像素(因为3.5 * 64 / 4.0 = 56)

顺便提及,量化的密度也定义了在布局文件中指定的DP的物理尺寸。该公式为:

Incidentally, the quantized density also defines the physical size of the dp that you specify in your layout files. The formula for this is:

+=======================+
|          Dq           |
|   1dp = ----- px      |
|          160          |
+=======================+

,其中DQ为量化的密度。例如,

where Dq is the quantized density. For example,

  • 在设备的DQ为160,1DP = 1px的
  • 的Dq上的设备,其为240,1DP = 1.5px
  • 在设备的DQ为320,1DP = 2px的

这篇关于如何量化密度影响图像资源选择和缩放?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆