【问题标题】:DPI Percentage Scaling to actual DPI valueDPI 百分比缩放到实际 DPI 值
【发布时间】:2017-01-19 08:58:48
【问题描述】:

据我们所知,Windows 7 可用的 DPI 缩放比例为 100%、125%、150% 和 200%。 这四个 DPI 百分比的实际 DPI 值为

Percentage - DPI Values
100%       - 96
125%       - 120
150%       - 144
200%       - 192

参考 DPI 缩放的链接: http://www.techrepublic.com/blog/windows-and-office/get-a-better-view-in-windows-7-by-adjusting-dpi-scaling/

使用 C# 我想获取 DPI 值。所以通过遵循 C# 代码我试图实现。

float x=0;
float y=0;
Graphics gp = Graphics.FromHwnd(IntPtr.Zero);// we can also use this.CreateGraphics()
x = gp.DpiX;
y = gp.DpiY;

得到如下输出,150% 和 200% 是错误的

100%  -  96 //both x,y values
125%  - 120 //both x,y values
**150%  -  96 //both x,y values
200%  -  96 //both x,y values**

【问题讨论】:

    标签: c# dpi


    【解决方案1】:

    如果您没有将您的应用程序声明为“DPI 感知”,Windows 会欺骗您,假装它设置为 96 DPI(尽管不是)并负责扩展您的应用程序本身。

    您可以通过以下任一方式“修复”此问题

    • dpiAware-条目添加到您的应用程序清单文件或
    • 调用SetProcessDPIAware Windows API 方法。

    例如,可以在这个 SO 答案中找到两者的示例:

    为了让事情变得更加复杂,Windows 8.1 引入了每个显示器的 DPI 设置,弃用了 SetProcessDPIAware。这其实是好事,不过it's hard to get it right

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-15
    • 2012-02-22
    • 2014-11-22
    • 1970-01-01
    • 1970-01-01
    • 2020-05-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多