How can I get the DPI in WPF?
+6
A:
http://blogs.msdn.com/jaimer/archive/2007/03/07/getting-system-dpi-in-wpf-app.aspx seems to work
PresentationSource source = PresentationSource.FromVisual(this);
double dpiX, dpiY;
if (source != null) {
dpiX = 96.0 * source.CompositionTarget.TransformToDevice.M11;
dpiY = 96.0 * source.CompositionTarget.TransformToDevice.M22;
}
Paul Betts
2009-12-17 01:17:46
This is exatly what I needed, thanks!
tom greene
2009-12-17 01:49:58
Keep in mind though that WPF units aren't pixels, they're device-independent @ 96DPI "pixelish-units"; so really what you want, is the scale factor between 96DPI and the current DPI (so like 1.5 for 144DPI)
Paul Betts
2009-12-17 01:51:40
So that's not what I need then :( How do I get the scale factor?
tom greene
2009-12-17 18:02:44
Should I use GetDeviceCaps (.., LOGPIXELSX)?
tom greene
2009-12-17 18:10:54
@tom it's just [dpiX, dpiY] / 96.0
Paul Betts
2009-12-17 23:06:53