How do I get an Icon from a png image? How do I get an Icon from a png image? wpf wpf

How do I get an Icon from a png image?


I think you can try something like this before convert your image to .ico:

    var bitmap = new Bitmap("Untitled.png"); // or get it from resource    var iconHandle = bitmap.GetHicon();    var icon = System.Drawing.Icon.FromHandle(iconHandle);

Where icon will contain the icon which you need.


There's also a website (http://www.convertico.com/) which converts PNGs into ICOs.


Icons are a combination of 3 or 4 image sizes:

48 × 48, 32 × 32, 24 × 24 (optional), and 16 × 16 pixels.

And can/should also contain three different colour depths:

  • 24-bit with 8-bit alpha (32-bit)
  • 8-bit (256 colors) with 1-bit transparency
  • 4-bit (16 colors) with 1-bit transparency

So the .png memory stream isn't going to fit into the icon's constructor. In fact, if you read the notes on the other constructor overloads, you'll see all the "Size" or Width and Height measurements for finding the correct size icon in the file.

More information on the manual creation of icons can be found under "Creating Windows XP Icons"