0

I write the c# windows program for convert the all image into .ico file.But the .ico only suited for favicon only not for folder image

Here is my code

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

Second line is use for convert the image into .ico file.

Anybody know how to solve this?

r.vengadesh
  • 1,721
  • 3
  • 20
  • 36

3 Answers3

1

Please check https://stackoverflow.com/a/3215441/361100 link to create multiple sized ico file.

The post guides you to go to http://www.vbforums.com/showthread.php?396650-Create-Valid-Icon-Files!-In-24-bit-true-color! link and I seems to work well.

I will remove wrongly pointed post to apply ico to folder.

-- REMOVED --

Community
  • 1
  • 1
Youngjae
  • 24,352
  • 18
  • 113
  • 198
  • i think your code used for changing folder image.But i dont want that.I am asked why my output (.ico image) not suited for folder image? – r.vengadesh Jun 20 '13 at 08:02
  • Sorry for the wrong point. I think you have to make it with multiple sized ico files not a single sized ico file. – Youngjae Jun 20 '13 at 08:06
  • yes i create multiple sized .ico file.Is this make any problem for folder image? – r.vengadesh Jun 20 '13 at 08:08
  • I hardly think so. hmm... have you apply it with my removed method? – Youngjae Jun 20 '13 at 08:11
  • But i change the image size 50x50.But the image not suited. – r.vengadesh Jun 20 '13 at 08:22
  • 1
    image sizes have to be matched for Windows to apply. exactly. 50x50 is not acceptable. please check this article in order to check proper sizes: http://msdn.microsoft.com/en-us/library/aa511280.aspx – Youngjae Jun 20 '13 at 08:30
1

In short, you need to include icons of size 16x16, 32x32, and 48x48, which GetHicon is not very good at when creating 32-bit icons. You can use FreeImage to create multi-resource icons as long as you only need 32-bit icons.

Please see my answer to your related question here for a code example: Convert image to icon in c#

Community
  • 1
  • 1
Mathew Eis
  • 280
  • 1
  • 2
  • 7
-2

This code will work:

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.

Then if you want to save it do this:

FileStream fs = new FileStream(@"c:\Icon\" + filename + ".ico", FileMode.OpenOrCreate);//Write Icon to File Stream
 newIcon.Save(fs);
r.mirzojonov
  • 1,209
  • 10
  • 18
  • you copied my code and paste this page see the stackoverflow who asked that question? – r.vengadesh Jun 20 '13 at 14:20
  • Yeah that's right but I wanted to help the person who asked this question. One mystery I had with this code, I've saved the icon, when I renamed it an ugly icon became better in look. – r.mirzojonov Jun 20 '13 at 14:37