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

  • 相关阅读:
    CAST和CONVERT
    #pragma 预处理指令详解
    Android系统移植主要事项
    Java动态绑定机制的内幕
    Java接口和抽象类用法总结
    Android工程的编译过程
    点击按钮,并且实现增加一个按钮的效果 (附效果图)
    iOS-设置导航栏"返回"按钮 (附效果图)
    常用代码整理(重要)
    NSTimer 的暂停与恢复运行。
  • 原文地址:https://www.cnblogs.com/lisengl/p/4169464.html
Copyright © 2011-2022 走看看