dingli

方法一:用ManagementClass来获取。需要引入System.Management.dll;

 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();
                }
            }
View Code

方法二:用Graphics来获取。需要引入 System.Drawing.dll ;

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

 

分类:

技术点:

相关文章:

  • 2021-11-01
  • 2021-11-01
  • 2022-01-07
  • 2021-11-18
  • 2021-12-18
  • 2018-06-01
猜你喜欢
  • 2021-10-19
  • 2021-08-12
  • 2021-11-01
  • 2022-01-08
  • 2021-12-10
  • 2021-11-18
  • 2021-09-02
相关资源
相似解决方案