获取设备DPI(IOS ,ANDROID)

11 篇文章 0 订阅
ios获取ppi方法:

#include <sys/types.h>#include <sys/sysctl.h>
    
size_t size; sysctlbyname( "hw.machine" , NULL, &size, NULL,  0 ); char  *machine = malloc(size); sysctlbyname( "hw.machine" , machine, &size, NULL,  0 ); NSString *platform = [NSString  stringWithUTF8String: machine]; free(machine); if ( [platform  hasPrefix: @ "iPhone1" ] || [platform  hasPrefix: @ "iPhone2" ] || [platform  hasPrefix: @ "iPhone3" ]) return   163.0 f; if ( [platform  hasPrefix: @ "iPhone4" ] || [platform  hasPrefix: @ "iPhone5" ] || [platform  hasPrefix: @ "iPhone6" ]) return   326.0 f;         //      // For iPhone6+      // Added by Gerry 2014.11.22 10:12      //      // Note: iPhone6  326ppi      if ( [platform  hasPrefix: @ "iPhone7" ]) {         return   401.0 f;    } if ( [platform  hasPrefix: @ "iPhone" ])  // catch-all for higher-end devices not yet existing { return   326.0 f; } if ( [platform  hasPrefix: @ "iPod1" ]    || [platform  hasPrefix: @ "iPod2" ]    || [platform  hasPrefix: @ "iPod3" ]) return   163.0 f; if ( [platform  hasPrefix: @ "iPod4" ]    || [platform  hasPrefix: @ "iPod5" ]) return   326.0 f; if ( [platform  hasPrefix: @ "iPod" ])  // catch-all for higher-end devices not yet existing { return   326.0 f; } if ( [platform  hasPrefix: @ "iPad1" ] || [platform  hasPrefix: @ "iPad2" ]) return   132.0 f; if ( [platform  hasPrefix: @ "iPad3" ] || [platform  hasPrefix: @ "iPad4" ]) return   264.0 f; if ( [platform  hasPrefix: @ "iPad" ])  // catch-all for higher-end devices not yet existing { return   264.0 f; } if ( [platform  hasPrefix: @ "x86_64" ]) { return 132.0f
}

android 获取DPI方法:
DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); float density = dm.densityDpi;
return density;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值