zoukankan      html  css  js  c++  java
  • 像素和毫米的换算

    屏幕PPI计算: (White^2+Height^2)^0.5/屏幕大小英寸数

    毫米和像素换算:    mm=(px/dpi)*25.4        px=(mm*dpi)/25.4

             英寸=px/dpi

             1英寸=25.4毫米

    dpi获取:

    方法1.

    using (Graphics graphics = Graphics.FromHwnd(IntPtr.Zero))
                {
                    float dpiX = graphics.DpiX;
                    float dpiY = graphics.DpiY;
                }

    方法2.

    using (ManagementClass mc = new ManagementClass("Win32_DesktopMonitor"))
                {
                    using (ManagementObjectCollection moc = mc.GetInstances())
                    {

                        int PixelsPerXLogicalInch = 0; // dpi for x
                        int PixelsPerYLogicalInch = 0; // dpi for y

                        foreach (ManagementObject each in moc)
                        {
                            PixelsPerXLogicalInch = int.Parse((each.Properties["PixelsPerXLogicalInch"].Value.ToString()));
                            PixelsPerYLogicalInch = int.Parse((each.Properties["PixelsPerYLogicalInch"].Value.ToString()));
                        }

                        Console.WriteLine("PixelsPerXLogicalInch:" + PixelsPerXLogicalInch.ToString());
                        Console.WriteLine("PixelsPerYLogicalInch:" + PixelsPerYLogicalInch.ToString());
                        Console.Read();
                    }
                }

    获取DPI方法参考:http://www.cnblogs.com/dingli/p/3187217.html

  • 相关阅读:
    Xdebug
    单点登录
    一个Https网站发送Http的 ajax请求的解决方法
    js关闭微信浏览器页面
    标准的身份证验证(第18位校验码)
    Redis 更新(set) key值 会重置过期时间问题
    PHP 报错:Deprecated: Methods with the same name as their class will not be constructor...
    php防sql注入
    web开发原则
    fopen()函数
  • 原文地址:https://www.cnblogs.com/lisengl/p/4169464.html
Copyright © 2011-2022 走看看