以编程方式编辑特定分辨率的图标。

4
在我的WinForms应用程序中,我可以使用this.Icon更改任务栏图标,但这也会更改标题栏中的应用程序图标。
以下是我目前编辑图标的方式:
public static Icon GetIcon(string text)
{
    //Create bitmap, kind of canvas
    Bitmap bitmap = new Bitmap(32, 32);

    Icon icon = new Icon(@"<icon-location>");
    System.Drawing.Font drawFont = new System.Drawing.Font("Calibri", 12, FontStyle.Bold);
    System.Drawing.SolidBrush drawBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Orange);

    System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bitmap);

    graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixel;
    graphics.DrawIcon(icon, 0, 0);
    graphics.DrawString(text, drawFont, drawBrush, 20, 15);


    Icon createdIcon = Icon.FromHandle(bitmap.GetHicon());

    drawFont.Dispose();
    drawBrush.Dispose();
    graphics.Dispose();
    bitmap.Dispose();

    return createdIcon;
}

直到需求变更,现在只需要更改任务栏图标而不更改标题栏(应用程序窗口左上角)图标,这就成为了一个问题。
经过一些搜索,我找到了这个答案,基本上说明不同的分辨率被用于在不同的位置显示图标。该答案中提到的“Greenfish Icon Editor Pro”效果很好,但我的编辑需要在运行时进行,因为它被用作通知方法,以通知用户未读通知的数量,所以这不是一次性编辑。
我意识到我需要更改图标的64x64像素才能实现我的目标,但到目前为止,我只能整体更改图标。
有没有办法编辑< strong > GetIcon() 函数以编辑特定的图标分辨率?(或者至少建议另一种替代方法将不胜感激)
1个回答

2
您所询问的是:
如何通过编程创建多图标?
.NET 的标准 Icon 类并没有提供这样的功能,因为 .NET 没有 ICON 编码器,可以参考 this article 以了解证明。
顺便说一下,您可以创建自己的编码器来创建多图标,幸运的是,您不需要这样做,因为已经有一些好心人已经做过了。以下是一些有用的链接: 希望能对您有所帮助。

我使用了 VB 示例线程 中的 IconEX DLL,结合 GetIcon() 函数。谢谢 - Reyno

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接