【问题标题】:Create System Tray Icon from Webdings font从 Webdings 字体创建系统托盘图标
【发布时间】:2018-01-02 12:15:37
【问题描述】:

我正在尝试创建一个非常简单的系统托盘图标,它只是一个带有白色边框的动态彩色圆圈。为此,我们使用 Webdings 字体。 Webdings 中的“n”只是一个普通的圆圈。

我目前正在做的事情几乎就在那里,但在某些 PC(但不是全部)上,它最终会出现一个波涛汹涌、难看的黑色边框:

这是我得到的:

protected static Icon GetTrayIconFromCache(Color statusColor)
{
    Bitmap bmp = new Bitmap(16,16);                            
    Graphics circleGraphic = Graphics.FromImage(bmp);
    circleGraphic.DrawString("n", new Font("Webdings", 12F, FontStyle.Regular), Brushes.White, -3f, -2f);
    circleGraphic.DrawString("n", new Font("Webdings", 9F, FontStyle.Regular), new SolidBrush(statusColor), 0f, -1f);
    Icon ico = Icon.FromHandle((bmp).GetHicon());
    return ico;
}

无论我怎么尝试,我都无法摆脱圆圈外那些难看的黑点。它们不会出现在每个人面前......一些开发人员看不到它,它看起来清晰干净。我们还没有弄清楚那些看起来不错的 PC 和不好看的 PC 之间的共性是什么。

但是……有没有更好的方法来做到这一点?

【问题讨论】:

  • 为什么不使用两个位图呢?
  • 可能是那些带有丑陋边框的屏幕分辨率不同,或者他们可能在显示设置中禁用了cleartype?
  • @Isma,因为内圈的颜色需要是动态的。它代表一种状态颜色,在应用程序中,用户可以将其状态设置为他们想要的任何颜色。
  • @LocEngineer,cleartype 很可能是问题所在,但我们不能强制用户设置它,以便我们的系统尝试图标看起来不错。 必须有一种方法可以生成无论哪种方式看起来都很清晰的图标。
  • Bitmap.GetHIcon() 很麻烦,它只支持生成一个包含16种颜色的调色板的图标。在包含抗锯齿文本或线条艺术的位图上,这永远不会结束。考虑this code。您可能需要使用 SystemInformation.IconSize 而不是硬编码 16x16 以避免调整尺寸的工件破坏抗锯齿效果。

标签: c# .net windows icons


【解决方案1】:

添加TextRenderingHint 的AntiAliasGridFit。

protected static Icon GetTrayIconFromCache(Color statusColor)
{
    Bitmap bmp = new Bitmap(16,16);                            
    Graphics circleGraphic = Graphics.FromImage(bmp);

    circleGraphic.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;

    circleGraphic.DrawString("n", new Font("Webdings", 12F, FontStyle.Regular), Brushes.White, -3f, -2f);
    circleGraphic.DrawString("n", new Font("Webdings", 9F, FontStyle.Regular), new SolidBrush(statusColor), 0f, -1f);
    Icon ico = Icon.FromHandle((bmp).GetHicon());
    return ico;
}

【讨论】:

  • 成功了!非常感谢您!
猜你喜欢
  • 2017-05-21
  • 2018-03-07
  • 1970-01-01
  • 2011-11-11
  • 1970-01-01
  • 2016-08-22
  • 1970-01-01
  • 2017-02-03
  • 2011-04-16
相关资源
最近更新 更多