« John Piper's Candidating Sermon at Bethlehem Baptist | Main | Andale in Palo Alto is closing... »

"Image format is unrecognized" when setting WPF Window Icon


Vista allows embedding 256x256 png images inside of .ico files. This can be generated, for example, by an application such as IcoFX. Unfortunately, at least as of .NET 3.0, the WPF Window Icon cannot accept this. The problem does not lie in the IconBitmapDecoder, but appears to lie in the Window code. To set the Icon property in code, we can do the following:

IconBitmapDecoder ibd = new IconBitmapDecoder(s, BitmapCreateOptions.None, BitmapCacheOption.Default);
this.Icon = ibd.Frames[0];

Where "s" is your .ico stream. If you have a Vista-style .ico file, setting Icon will trigger the "image format is unrecognized" error. The only way to resolve this is to generate the .ico without the Vista images*.

donotcompress.png

Now, take a cleansing breath, smile, and get back to work.

*MSDN discussion.

Comments (3)

You are a pimp! Thanks for posting this... you saved the day.

You are a pimp! Thanks for posting this... you saved the day.

extinction compliance decade taken android

Post a comment


Please enter the security code you see here

About

This page contains a single entry from the blog posted on January 16, 2009 11:58 AM.

The previous post in this blog was John Piper's Candidating Sermon at Bethlehem Baptist.

The next post in this blog is Andale in Palo Alto is closing....

Many more can be found on the main index page or by looking through the archives.

Creative Commons License
This weblog is licensed under a Creative Commons License.
Powered by
Movable Type 3.35