Is there a way to retrieve a device's DPI without using GDI+/WinForms "Graphics" class?

Someone asked on Stack Overflow:

Is it possible to get my devices DPI from c# using a native win api call?

I know how to get the dpi from a windows forms application and the current code I have is:

  Graphics g = Graphics.FromImage(new Bitmap(10, 10));

  var scaleX = g.DpiX / 96.0f;
  var scaleY = g.DpiY / 96.0f;

I was wondering if the is a win api call that can make things easier.

I posted the following answer, which was chosen as the accepted answer and received 2 upvotes:

What about a WMI Query to the Win32_DesktopMonitor class?

PixelsPerXLogicalInch

Data type: uint32
Access type: Read-only
Qualifiers: Units (Pixels per Logical Inch) 

Resolution along the x-axis (horizontal direction) of the monitor.

PixelsPerYLogicalInch

Data type: uint32
Access type: Read-only
Qualifiers: Units (Pixels per Logical Inch) 

Resolution along the y-axis (vertical direction) of the monitor.

You might use it similar to this question:

ManagementObjectSearcher monitorObjectSearch = new ManagementObjectSearcher("SELECT * FROM Win32_DesktopMonitor");

foreach (ManagementObject monitor in monitorObjectSearch.Get())
{
      Debug.WriteLine(monitor["PixelsPerXLogicalInch");
      Debug.WriteLine(monitor["PixelsPerYLogicalInch");
}

There is also the Windows API Route with GetDeviceCaps, but I’ve read that there are some issues with it on Windows 7 so your mileage may be different.

There is also the Direct2D GetDesktopDpi (mentioned by Alex), which looks like it would require doing some COM Interop calls, and may or may not be as clean and will only work Windows versions where Direct2D is available. Some additional information on Direct2D and .NET.


Originally posted on Stack Overflow — 2 upvotes (accepted answer). Licensed under CC BY-SA.

signed letter b

Dad. Geek. Gamer. Software developer. Cloud user. Old Car enthusiast.  Blogger.


Top Posts


profile for Nate on Stack Exchange, a network of free, community-driven Q&A sites
a proud member of the blue team of 512KB club
Thoughts, opinions, and ideas shared here are my own. © 2026 Nate Bross.