Article Index

Dynamically Generating Icons, safely

My development efforts went on a major tangent recently when I discovered there was no "safe" way to dynamically generate an icon in the .NET Framework (using Icon.FromHandle() requires the UnmanagedCode SecurityPermission).  What was supposed to be a very minor feature of an application - updating a tray icon with custom text - turned into a major time sucker.  I was forced to learn the innards of the Bitmap and Icon file formats and write my own conversion code.  Isn't this the kind of coding the .NET Framework is supposed to prevent?  We should be writing business logic, not common image format conversion routines.  I'm not attacking .NET in general, there is no question it has made me more productive, I'm just a little bitter that I got bitten by one of the edge cases. (I have to admit, I enjoyed doing the "low level" coding for a while, I just wasn't planning on the time requirement)

Anyway, the good news is, I did it, and now it's done.  I wrote the code so you don't have to.  I have posted it as my first ever article on The Code Project.  Check it out and let me know what you think.

Comments

Thanks for the code. I found it helps also when you're getting generic GDI+ errors.

Of course, now a "little" app sits in the systray sucking major CPU. If you know anything about that, I'd love to hear about it.
Jamie - February 23, 2006 03:24pm