从Webdings字体创建系统托盘图标

问题描述 投票:3回答:1

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

我目前正在做的几乎就在那里,但是在一些PC(但不是全部)上,它最终会在它周围形成一个波涛汹涌的黑色边框:

enter image description here

这是我得到的:

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之间的共性。

但是......有更好的方法吗?

c# .net windows icons
1个回答
5
投票

添加TextRenderingHintAntiAliasGridFit

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;
}
© www.soinside.com 2019 - 2024. All rights reserved.