屏幕密度和分辨率之间的关系

时间:2019-03-22 12:22:12

标签: android

我正在查看android文档,其中解释了有关屏幕密度,不同屏幕密度和分辨率的概念。

如果我理解正确,

resolution is the total absolute no of pixels that are shown on the screen

density is the number of pixels per inch

现在,我正在经历this doc,它说:

  

系统图库应用程序显示使用您的Android设备的摄像头拍摄的照片,这些照片的分辨率通常比设备的屏幕密度高

这句话让我再次感到困惑。如何将图像的分辨率与屏幕的密度进行比较?

或者只是说图像的分辨率会比屏幕的分辨率高吗?

2 个答案:

答案 0 :(得分:1)

这只是文档中术语的不幸使用。

图片具有特定分辨率:X像素高,Y像素宽。如果屏幕的分辨率与图片相同或更高,则可以按原样显示整个图片。否则,需要将图片“压缩”到可用空间中。

请注意,这与屏幕的密度无关。具有相同分辨率的Denser屏幕在物理上只会更小,因为密度与每个像素的物理尺寸成反比。

答案 1 :(得分:1)

假设您的手机以4000x3000像素的分辨率拍摄照片。

假设您使用的iPhone X的像素为var canvas = document.createElement("canvas"); canvas.width = ??; canvas.height = ??; var ctx = canvas.getContext("2d"); // draw an arraw and rounded box ..... ..... var iconUrl = canvas.toDataURL(); var offStyle = new ol.style.Style({ fill: new ol.style.Fill({ color: 'rgba(255,255,255,0)' }), stroke: new ol.style.Stroke({ color: 'green', width: 1.5 }) }); var onStyle = new ol.style.Style({ fill: new ol.style.Fill({ color: 'rgba(255,255,255,0)' }), stroke: new ol.style.Stroke({ color: 'black', width: 1.5 }) }); var styleFunction = function (feature, resolution) { if (off) { // or use (resolution > ????) return offStyle; else { var styles = [onStyle]; if (feature.getGeometry().getType == 'Polygon') { styles.push( new ol.style.Style({ geometry: feature.getGeometry().getInteriorPoint(), image: new ol.style.Icon({ src: iconUrl, // options to anchor the icon .... }), text: new ol.style.Text({ scale: 1, text: feature.get('.....'), font: 'normal 10px FontAwesome', fill: new ol.style.Fill({ color: 'black' }), }), zIndex: 100 })); } return styles; } } 为458 ppi,并且手机的尺寸为5.69x2.79英寸,因此它可以容纳的总像素几乎为(1125 x 2436像素) 这意味着在100%缩放的图像中,它只能适合屏幕上的一部分。

相关问题