Original: C # gets the current screen dpi
1. Get through the Graphics class
Graphics currentgraphics = Graphics.fromhwnd (new windowinterophelper (MainWindow). Handle); double dpixratio = currentgraphics.dpix/;
For example, the current screen setting dpi setting 1.5 times times, can be obtained through the background as above.
2. By Win32-managementclass
using(ManagementClass MC =NewManagementClass ("Win32_DesktopMonitor")){ using(Managementobjectcollection MOC =MC. GetInstances ()) {intPixelsperxlogicalinch =0;//dpi for x intPixelsperylogicalinch =0;//dpi for y foreach(ManagementObject eachinchMOC) {Pixelsperxlogicalinch=int. Parse (each. properties["Pixelsperxlogicalinch"]. Value.tostring ())); Pixelsperylogicalinch=int. Parse (each. properties["Pixelsperylogicalinch"]. Value.tostring ())); } }}
It is worth mentioning that, with the main screen in the case, is not able to get the dpi of the secondary screen!
Note: Physical resolution/real resolution/aspect scaling of the screen, refer to C # API for system DPI zoom and resolution size
C # Gets the current screen dpi