title: How do I display a Windows file icon in WPF?
body: <p>Currently I'm getting a native icon by calling SHGetFileInfo. Then, I'm converting it to a bitmap using the following code. The Bitmap eventually gets displayed in the WPF form.</p>
  
  <p>Is there a faster way to do the same thing?</p>
  
  <pre><code>try
          {
              using (Icon i = Icon.FromHandle(shinfo.hIcon))
              {
                  Bitmap bmp = i.ToBitmap();
                  MemoryStream strm = new MemoryStream();
                  bmp.Save(strm, System.Drawing.Imaging.ImageFormat.Png);
                  BitmapImage bmpImage = new BitmapImage();
                  bmpImage.BeginInit();
                  strm.Seek(0, SeekOrigin.Begin);
                  bmpImage.StreamSource = strm;
                  bmpImage.EndInit();
  
                  return bmpImage;
              }
          }
          finally
          {
              Win32.DestroyIcon(hImgLarge);
          }
  </code></pre>