I need to write a program that will generate 108 combinations of icons (standard windows .ico files) based on a tile image.
I use the System.Drawing.Bitmap class to build each combinaison, and I save them as follows:
Bitmap IconBitmap = new Bitmap(16, 16); // Some processing, writing different parts of the source tileset // ... IconBitmap.Save(Path.Combine(TargetPath, "Icon" + Counter + ".ico"), ImageFormat.Icon);
But I found out that the saved file is actually PNG. Neither Windows Explorer nor Visual Studio can display it correctly, but GIMP can, and if I open it in the Hex viewer, this is what I see:
00000000 89 50 4E 47 0D 0A 1A 0A 00 00 00 0D 49 48 44 52 ‰PNG........IHDR 00000010 00 00 00 10 00 00 00 10 08 06 00 00 00 1F F3 FF ..............óÿ 00000020 61 00 00 00 01 73 52 47 42 00 AE CE 1C E9 00 00 a....sRGB.®Î.é.. 00000030 00 04 67 41 4D 41 00 00 B1 8F 0B FC 61 05 00 00 ..gAMA..±..üa... 00000040 00 09 70 48 59 73 00 00 0E C3 00 00 0E C3 01 C7 ..pHYs...Ã...Ã.Ç 00000050 6F A8 64 00 00 00 15 49 44 41 54 38 4F 63 60 18 o¨d....IDAT8Oc`. 00000060 05 A3 21 30 1A 02 A3 21 00 09 01 00 04 10 00 01 .£!0..£!........ 00000070 72 A5 13 76 00 00 00 00 49 45 4E 44 AE 42 60 82 r¥.v....IEND®B`‚
Also, if I rename .ico to .png, Windows Explorer may display it correctly.
I have this result, even if I have NOTHING in the bitmap (I directly build it with new and Save , which gives me black png).
What am I doing wrong?
I also tried this, which gave me an awful 16 color icons, but I would prefer to avoid this solution anyway (using the pens):
Icon NewIcon = Icon.FromHandle(IconBitmap.GetHicon()); FileStream FS = new FileStream(Path.Combine(Target, "Icon" + Counter + ".ico"), FileMode.Create); NewIcon.Save(FS);
c # bitmap png icons system.drawing
Benlitz
source share