0

我编写了用于将所有图像转换为 .ico 文件的 c# windows 程序。但 .ico 仅适用于 favicon,不适用于文件夹图像

这是我的代码

Image theImage = Image.FromFile(textBox1.Text);
Bitmap theBitmap = new Bitmap(theImage, new Size(width, height));

第二行用于将图像转换为 .ico 文件。

有人知道如何解决这个问题吗?

4

3 回答 3

1

简而言之,您需要包含大小为 16x16、32x32 和 48x48 的图标,GetHicon 在创建 32 位图标时不太擅长这些。只要您只需要 32 位图标,就可以使用 FreeImage 创建多资源图标。

请在此处查看我对您的相关问题的回答以获取代码示例: Convert image to icon in c#

于 2013-06-26T06:02:53.960 回答
1

请检查https://stackoverflow.com/a/3215441/361100链接以创建多个大小的ico文件。

该帖子将引导您访问http://www.vbforums.com/showthread.php?396650-Create-Valid-Icon-Files!-In-24-bit-true-color!链接,我似乎工作得很好。

我将删除错误指向的帖子以将 ico 应用于文件夹。

-- 已移除 --

于 2013-06-20T07:58:47.117 回答
-2

此代码将起作用:

Bitmap theBitmap = new Bitmap(theImage, new Size(width, height));
IntPtr Hicon = theBitmap.GetHicon();// Get an Hicon for myBitmap.
Icon newIcon = Icon.FromHandle(Hicon);// Create a new icon from the handle.

然后,如果您想保存它,请执行以下操作:

FileStream fs = new FileStream(@"c:\Icon\" + filename + ".ico", FileMode.OpenOrCreate);//Write Icon to File Stream
 newIcon.Save(fs);
于 2013-06-20T14:15:25.633 回答