title: WPF - ImageSource for Window Icon from base 64 string (or byte array)
body: <p>I'm in WPF and I'm using a WCF service to pull images as base 64 encoded strings.  I convert the base 64 encoded strings to ImageSource to assign to Image.Source.  I wrote a test app to test the process, and everything seemed to work fine as long as I only used the ImageSource for an Image.Source.  But I also need to use some ImageSources for window icons.  Here's what I'm trying to do:</p>
  
  <pre><code>ImageSource src = Util.Base64StringToImageSource(tbxBase64String.Text);
  //img is a System.Windows.Controls.Image
  img.Source = src; //This works just fine
  //Class is a Window, so Icon is this.Icon (System.Windows.Window.Icon)
  Icon = src; //This throws an InvalidOperationException - "ImageSource for Icon property must be an icon file."
  </code></pre>
  
  <p>And here's the conversion method:</p>
  
  <pre><code>public static System.Windows.Media.ImageSource Base64StringToImageSource(string base64String)
  {
      using (MemoryStream stream = new MemoryStream(Convert.FromBase64String(base64String)))
      {
          System.Windows.Media.Imaging.BitmapImage bi = new System.Windows.Media.Imaging.BitmapImage();
          bi.BeginInit();
          bi.StreamSource = stream;
          bi.CacheOption = System.Windows.Media.Imaging.BitmapCacheOption.OnLoad;
          bi.EndInit();
          bi.Freeze();
          return bi;
      }
  }
  </code></pre>
  
  <p>I need to know how to get an ImageSource that can be used for a Window Icon from a base 64 string (or byte array).</p>