https://facebook.github.io/react-native/docs/pixelratio.html
import {PixelRatio, Platform,Dimensions} from 'react-native';
var window = require('Dimensions').get('window');
export const maxHeight = PixelRatio.getPixelSizeForLayoutSize(Dimensions.get('window').height);
export const maxWidth = PixelRatio.getPixelSizeForLayoutSize(Dimensions.get('window').width);
export const scaleHeight = maxHeight/768;
export const scaleWidth = maxWidth/1024;
export const pixRa = PixelRatio.get();
export const px2dp = (px) => {
return px / PixelRatio.get();
}
export const dp2px = (dp) => {
return dp * PixelRatio.get();
}
export const getRealDpWidth = (number) => {
return px2dp(number)*scaleWidth;
}
export const getRealDpHeight = (number) => {
return px2dp(number)*scaleHeight;
}
export const getRealDpWidthZyx = (number) => {
return Dimensions.get('window').width/1024 * number;
}
export const getRealDpHeightZyx = (number) => {
return Dimensions.get('window').height/768 * number;
}
const a1 = getRealDpHeight(44);
const a11 = getRealDpHeightZyx(44);
console.log('--' + a1 +" "+ a11);
const b1 = getRealDpWidth(33);
const b11 = getRealDpWidthZyx(33);
console.log('--' + b1 +" "+ b11);
http://blog.csdn.net/ridxmc/article/details/51346472
ppi (pixels per inch):屏幕像素密度 (在图像中,每英寸所包含的像素数目)
dpi (dots per inch): 打印分辨率 (每英寸所能打印的点数,即打印精度)
pt:iOS开发单位,即point,绝对长度,1pt=1/72英寸。
可以看出iphone的屏幕密度只有3种,即
@1x,163ppi(iphone3gs)
@2x,326ppi(iphone4、4s、5、5s、6)
@3x,401ppi(iphone6+)
一、基本概念
dip : Density independent pixels ,设备无关像素。
dp :就是dip
px : 像素
dpi :dots per inch , 直接来说就是一英寸多少个像素点。常见取值 120,160,240。我一般称作像素密度,简称密度
density : 直接翻译的话貌似叫 密度。常见取值 1.5 , 1.0
分辨率 : 横纵2个方向的像素点的数量,
屏幕尺寸: 屏幕对角线的长度。电脑电视同理。
屏幕比例的问题。因为只确定了对角线长,2边长度还不一定。所以有了4:3、16:9这种,这样就可以算出屏幕边长了。
不同PPI的dp与px的换算关系
160PPI(mdpi) : 1dp = 1px
240PPI(hdpi) : 1dp = 1.5px
320PPI(xhdpi) : 1dp = 2px
UI设计原型:基于iphone6
分辨率:1334 x 750 px;
屏幕大小:4.7英寸
320dpi
density=2
1dp=(1*density)px
DPI 326dpi(约等于,;)
全屏dp值:667 x 375 dp ((1334/density) x (750/density) )
https://segmentfault.com/a/1190000002658374
默认用的是ihone6的模拟器结果是:
window.width=375
window.height=667
export const maxHeight = PixelRatio.getPixelSizeForLayoutSize(Dimensions.get('window').height);
750
export const maxWidth = PixelRatio.getPixelSizeForLayoutSize(Dimensions.get('window').width);
1334
https://www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions