Monday, January 04, 2010

Vista Icons in .NET

As I have posted earlier, the .NET Framework has a problem with the 256x256 PNG icons that were introduced with Windows Vista.

I posted a bug report on Microsoft Connect explaining my findings and pointing them to my blog. They kindly mailed me earlier today that they were able to reproduce the behavior and are redirecting to the appropriated team.

I hope this time they will fix it, as I have done all the heavy lifting. Hehe!

Anyway, the basic problem with the System.Drawing.Icon class is the Initialize method. It searches for the wrong parameters (that I believe were right at the time).

Because the way it searchs for the difference in the icon size and the requested size AND the fact that a 256x256 icon reports its size, in the icon file structure, as 0x0, I was able to get an icon with 256x256 from the System.Drawing.Icon object by using a little bit of ingenuity: by asking for a 1x1 icon.

But although the Icon object reported its size as 256x256, when I called the ToBitmap() function, in order to get a proper image, an Exception was thrown.

However when I used a custom size of 255x255 PNG icon... The Icon class was able to get it right away. No need to work around anything.

So, if you need to have a 256x256 PNG icon in your .NET application AND have control of what icon you use, start using 255x255 custom sized icons instead.

0 Comments:

Post a Comment