I would like to create a single System.Drawing.Icon programmatically from 32x32, 16x16 Bitmaps. Is this possible? If I load an icon with -
Icon myIcon = new Icon(@"C:\myIcon.ico");
...it can contain multiple images.
I would like to create a single System.Drawing.Icon programmatically from 32x32, 16x16 Bitmaps. Is this possible? If I load an icon with -
Icon myIcon = new Icon(@"C:\myIcon.ico");
...it can contain multiple images.
There's a nice code snippet here. It uses the Icon.FromHandle
method.
An .ico file can have multiple images in it, but when you load an .ico file and create an Icon object, only one of those images is loaded. Windows chooses the most appropriate image based on the current display mode and system settings and uses that one to initialize the System.Drawing.Icon
object, ignoring the others.
So you can't create a System.Drawing.Icon
with multiple images, you have to pick one before you create the Icon
object.
Of course, It is possible to create an Icon at runtime from a bitmap, is that what you are really asking? Or are you asking how to create an .ico file?
You could try using png2ico to create a .ico file, invoking it using System.Diagnostics.Process.Start
. You would need to create your images and save them to disc before invoking png2ico.