I have a project that converts an image format file into an icon file. However, after converting the image, the color of the image changes.
Here is my code
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
Anybody know how to solve this?
In Solution Explorer, double-click the file app. ico. The Image Editor will open. Go to menu Image > Tools and select Text Tool.
Select your PNG, then click Open. Click Upload. Crop your image as needed, then scroll down and click Select None. Scroll all the way down and click Convert ICO.
Bitmap.GetHicon() is very good at creating icons that work well on any Windows version that can run .NET code. Including the old ones, Windows 98 and Windows 2000. Operating systems that did not yet support fancy icons.
So what you get is an icon with only 16 colors, using a pre-cooked palette with basic colors. This tends to generate disappointing results, to put it mildly.
The Bitmap or Icon classes do not have an option to get a better result. In general you'll need to use an icon editor to create good icons. Which should include multiple images in different sizes and color depths so they'll work well with any video adapter setting and any operating system version. Particularly color reduction from 16 million to 256 or 16 colors is a non-trivial operation with multiple ways to do it, none of them perfect. A good icon editor has the tools you need to make that work well enough.
UPDATE: getting to be a very dated problem, XP is yesteryear. Today you can generate a very good looking icon with this code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With