【问题标题】:Icons sizing not increasing in higher DPI图标大小在更高 DPI 中没有增加
【发布时间】:2018-09-12 06:45:09
【问题描述】:

我在 DPI 大于 100 时遇到了这个问题。我已经更改了图标的大小,例如粗体、斜体,当我以 100 dpi 运行程序时,图标大小更大,但是当我在之后运行程序时更改为大于 100 的 dpi 图标变得越来越小,并且没有更新为任何大小值。我试过 autosize = false, imagescaling to none.

【问题讨论】:

  • 什么语言/框架?给我们看一些代码!
  • 您需要在问题中添加更多详细信息,以便人们可以帮助您。

标签: highdpi dpi-aware


【解决方案1】:

使用 “System.Drawing.Icon” 图标,如果您使用大于 100 的 DPI,您应该记住使用更大尺寸的图标。属性 autosize 在这里没有帮助。

图标的文件可以包含不同的大小,因此我们可以检测实际的 DPI 比例因子,并考虑这个因子以从文件系统加载具有适当大小的图标。

检测DPI因子的代码如下:

    using System;
    using System.Drawing;
    using System.Runtime.InteropServices;

    public static class DpiHelper
    {
        private static readonly double m_dpiKoef = Graphics.FromHdc(GetDC(IntPtr.Zero)).DpiX / 96f;

        public static double GetDpiFactor()
        {
            return m_dpiKoef;
        }

        [DllImport("User32.dll")]
        private static extern IntPtr GetDC(IntPtr hWnd);
    }

现在使用 System.Drawing.Icon 中的 Icon(string fileName, int width, int height) 初始化图标的新实例如下所示:

int size = 48;
int dpiSize = (int)(size * DpiHelper.GetDpiFactor());
Icon dpiIcon = new Icon(filename, new Size(dpiSize, dpiSize));

【讨论】:

  • “DPI 因子”在 Windows 10 上不再固定。它可以在应用程序运行时更改。
猜你喜欢
  • 1970-01-01
  • 2017-07-09
  • 1970-01-01
  • 2017-04-03
  • 2019-05-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多