This may be a very simple problem, but I have not yet found the perfect solution. I am trying to convert png to ico with C # and found the question of converting .PNG to .ICO in C / C # , which seems to give a working solution, as shown below:
using (FileStream stream = File.OpenWrite(@"C:\temp\test.ico")) { Bitmap bitmap = (Bitmap)Image.FromFile(@"c:\temp\test.png"); Icon.FromHandle(bitmap.GetHicon()).Save(stream); }
For my own project, I slightly modified this approach:
string pngFile = "path/to/pngfile"; using (Bitmap bitmap = new Bitmap(pngFile)) { using (Icon icon = Icon.FromHandle(bitmap.GetHicon())) { using (MemoryStream stream = new MemoryStream()) { icon.Save(stream);
The problem I am facing is that as a result ico is of poor quality, I assume that it has changed to 16x16 and lost some of the color, maybe now it has only 16 colors? How can I convert to a better ico file?
Bazzz source share