I have an application which I have made a 256 x 256 Windows Vista icon for.
I was wondering how I would be able to use a 256×256 PNG file in the ico file used as the application icon and show it in a picture box on a form.
I am using VB.NET, but answers in C# are fine. I’m thinking I may have to use reflection.
I am not sure if this is even possible in Windows XP and may need Windows Vista APIs
Today, I made a very nice function for extracting the 256×256 Bitmaps from Vista icons.
Like you, Nathan W, I use it to display the large icon as a Bitmap in “About” box. For example, this code gets Vista icon as PNG image, and displays it in a 256×256 PictureBox:
This function takes Icon object as a parameter. So, you can use it with any icons – from resources, from files, from streams, and so on. (Read below about extracting EXE icon).
It runs on any OS, because it does not use any Win32 API, it is 100% managed code 🙂
IMPORTANT! If you want to load this icon directly from EXE file, then you CAN’T use Icon.ExtractAssociatedIcon(Application.ExecutablePath) as a parameter, because .NET function ExtractAssociatedIcon() is so stupid, it extracts ONLY 32×32 icon!
Instead, you better use the whole IconExtractor class, created by Tsuda Kageyu (http://www.codeproject.com/KB/cs/IconExtractor.aspx). You can slightly simplify this class, to make it smaller. Use IconExtractor this way:
Note: I’m still using my ExtractVistaIcon() function here, because I don’t like how IconExtractor handles this job – first, it extracts all icon formats by using IconExtractor.SplitIcon(icoAppIcon), and then you have to know the exact 256×256 icon index to get the desired vista-icon. So, using my ExtractVistaIcon() here is much faster and simplier way 🙂