标签:code bsp lin ges win32 des monit ctc png
1.通过Graphics类获取
Graphics currentGraphics = Graphics.FromHwnd(new WindowInteropHelper(mainWindow).Handle); double dpixRatio = currentGraphics.DpiX/96;
比如当前屏幕设置DPI设置1.5倍,可以通过如上通过后台获取。
2.通过Win32-ManagementClass
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())); } } }
值得一提的是,有主副屏屏幕的情况下,是获取不了副屏的DPI的!
标签:code bsp lin ges win32 des monit ctc png
原文地址:http://www.cnblogs.com/kybs0/p/7429282.html