标签: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