How can I get the DPI in WPF?

How can I get the DPI in WPF? Answer https://docs.microsoft.com/en-us/archive/blogs/jaimer/getting-system-dpi-in-wpf-app 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; } AttributionSource : Link , Question Author : tom greene , Answer Author : timelmer

How to configure an app to run correctly on a machine with a high DPI setting (e.g. 150%)?

I’ve created a simple Winforms application in C#. When I run the application on a machine with high DPI settings (e.g. 150%), the application gets scaled up. So far so good! But instead of rendering the fonts with a higher font size, all texts are just scaled up, too. That of course leads to very … Read more

How to write WinForms code that auto-scales to system font and dpi settings?

Intro: There’s a lot of comments out there that say “WinForms doesn’t auto-scale to DPI/font settings well; switch to WPF.” However, I think that is based on .NET 1.1; it appears they actually did a pretty good job of implementing auto-scaling in .NET 2.0. At least based on our research and testing so far. However, … Read more

Load dimension value from res/values/dimension.xml from source code

I’d like to load the value as it is. I have two dimension.xml files, one in /res/values/dimension.xml and the other one in /res/values-sw360dp/dimension.xml. From source code I’d like to do something like getResources().getDimension(R.dimen.tutorial_cross_marginTop); This works but the value I get is multiplied times the screen density factor (1.5 for hdpi, 2.0 for xhdpi, etc). I … Read more

getting the screen density programmatically in android?

How to get the screen density programmatically in android? I mean: How to find the screen dpi of the current device? Answer You can get info on the display from the DisplayMetrics struct: DisplayMetrics metrics = getResources().getDisplayMetrics(); Though Android doesn’t use a direct pixel mapping, it uses a handful of quantized Density Independent Pixel values … Read more