问题描述
大多数人使用96 DPI,但有时人们将其设置为120 DPI(甚至更高),特别是对于显示大于100 DPI的高分辨率显示器.这个数字很容易在Win32("LogPixels")下获得,并且我已经做了很多年了.但是我对.NET还是比较陌生,还无法找出.NET API提供了什么数字.这是一个非常重要的参数,因此必须有一个简单的API才能在.NET下获取它.有谁知道它是什么?从Vista以后的版本开始,这尤其重要,因为它不相信物理像素,而只相信独立于设备的单元.
Matthew MacDonald在C#2008中的 Pro WPF ,第1章对与设备无关的DPI缩放进行了很好的讨论,但是他没有说如何获得这个关键数字.我需要数字,因为我必须缩放从监视器枚举(指定x,y,高度和宽度)返回的数字,以用位图填充屏幕.所有这些数字都必须按比例缩小96/x,其中x是DPI缩放数字.
如果情况变得更糟,我将使用Interop服务获取该数字,但我畏惧每次这样做,以为我只是错过了.NET中的某些内容.
附录:我也可以从注册表中获取此编号:[HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows NT \ CurrentVersion \ FontDPI ]"LogPixels",但与Interop Services相比,它更像是一个黑客.最干净的方法是通过.NET API.
Most people use 96 DPI, but occasionally people set this to 120 DPI (or even higher), especially with high resolution monitors that display at greater than 100 DPI. This number is easy to get under Win32 ("LogPixels") and I''ve done it for years. But I''m relatively new to .NET and haven''t been able to find out what .NET API delivers this number. This is such an important parameter that there must be a simple API to get it under .NET. Does anyone know what it is? This is especially important from Vista onward which doesn''t believe in physical pixels, but merely device independent units.
Matthew MacDonald''s Pro WPF in C# 2008, chapter 1, has a good discussion of device independent DPI scaling but nowhere does he say how to obtain this crucial number. I need the number because I have to scale the numbers that come back from the monitor enumeration, which specifies, x,y, height, and width, to fill the screen with a bitmap. All these numbers have to be scaled back by a factor 96/x, where x is the DPI Scaling number.
If worse comes to worse, I''ll use Interop services to get the number, but I cringe every time I do that, thinking that I''ve just missed something in .NET.
Addendum: I can also get this number from the Registry: [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontDPI]"LogPixels" but that''s even more of a hack than Interop Services. The cleanest way would be through a .NET API.
推荐答案
这篇关于如何在.NET Framework中获取DPI缩放编号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!