C#计算屏幕的物理宽和高
var mc = new ManagementClass("Win32_DesktopMonitor"); double height = 0; double width = 0; foreach (var a in mc.GetInstances()) { string path; Trace.WriteLine(path = a.Properties["PNPDeviceID"].Value.ToString()); var bytes = (byte[])Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Enum\" + path + @"\Device Parameters").GetValue("EDID"); height = bytes[22]; width = bytes[21]; Trace.WriteLine("宽" + bytes[21].ToString()); Trace.WriteLine("高" + bytes[22].ToString()); } height = height * 10; width = width * 10; double x1 = SystemParameters.PrimaryScreenWidth;//得到屏幕整体宽度 double y1 = SystemParameters.PrimaryScreenHeight;//得到屏幕整体高度
要引用系统自带的Management.dll程序集,然后访问EDID的数据,EDID的数组中的22位和23位是屏幕的物理宽和高。
多看书,少装逼!