码迷,mamicode.com
首页 > 其他好文 > 详细

像素和毫米的换算

时间:2014-12-17 16:12:15      阅读:2504      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   ar   io   color   os   sp   

屏幕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

像素和毫米的换算

标签:des   style   blog   http   ar   io   color   os   sp   

原文地址:http://www.cnblogs.com/lisengl/p/4169464.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!