title: How do I get an Icon from a png image?
body: <p>I'm creating an WPF app, so I'm mostly working with the ImageSource class for icons. However, the system tray icon has to be of type <code>System.Drawing.Icon</code>. Is it possible to create such an object from a png image?</p>
  
  <p>I have tried the following:</p>
  
  <pre><code>private static System.Drawing.Icon _pngIcon;
  public static System.Drawing.Icon PngIcon
  {
      get
      {
          if (_pngIcon == null)
          {  
              //16x16 png image (24 bit or 32bit color)
              System.Drawing.Bitmap icon = global::BookyPresentation.Properties.Resources.star16;
              MemoryStream iconStream = new MemoryStream();
              icon.Save(iconStream, System.Drawing.Imaging.ImageFormat.Png);
              iconStream.Seek(0, SeekOrigin.Begin);
              _pngIcon = new System.Drawing.Icon(iconStream); //Throws exception
          }
          return _pngIcon;
      }
  }
  </code></pre>
  
  <p>The Icon constructor throws an exception with the following message: "Argument 'picture' must be a picture that can be used as a Icon."</p>
  
  <p>I figured it might be something with the bit depth of the image color as I had some issues with this earlier, but both 32bit and 24bit images didn't work. Is it possible what I'm trying to do?</p>