title: Convert System.Drawing.Bitmap to System.Windows.Media.BitmapImage for WPF
body: <p>I am receiving a bitmap as a string encoded in Base64. I am successfully turning this into a System.Drawing.Bitmap and displaying it on a test winforms in a picture box. Image shows without issues. </p>
  
  <p>However when i try and convert it to an BitmapImage i get a </p>
  
  <blockquote>
    <p>Metadata = 'image.Metadata' threw an exception of type
    'System.NotSupportedException'</p>
  </blockquote>
  
  <p>Below is the code im using to do the initial conversion and the conversion to a BitmapImage. The BitmapImage is required to pass to another method which requires an System.Windows.Media.ImageSource.</p>
  
  <pre><code>using (MemoryStream BitmapMS = new MemoryStream(Convert.FromBase64String(base64str)))
  {                    
      Bitmap bitmap = new Bitmap(BitmapMS);                    
      TestForm test = new TestForm();
      test.pictureBox1.Image = bitmap;
      test.ShowDialog();
  
      using (MemoryStream BitmapImageMS = new MemoryStream())
      {
          bitmap.Save(BitmapImageMS, ImageFormat.Jpeg);
          BitmapImageMS.Position = 0;
          var image = new BitmapImage();
          image.BeginInit();
          image.CacheOption = BitmapCacheOption.OnLoad;
          image.StreamSource = BitmapImageMS;
          image.EndInit();
          return image;
      }
  }
  </code></pre>
  
  <p>Edit: I should also mention im trying to use .Net 3.5</p>