title: byte[] to BitmapImage conversion fails
body: <p>I have a problem. I want to convert <code>BitmapImage</code> into <code>byte[]</code> array and back.</p>
  
  <p>I wrote these methods:</p>
  
  <pre><code>public static byte[] ToByteArray(this BitmapImage bitmapImage)
  {
      byte[] bytes;
      using (MemoryStream ms = new MemoryStream())
      {
          bitmapImage.BeginInit();
          bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
          bitmapImage.StreamSource.CopyTo(ms);
          bitmapImage.EndInit();
          bytes = ms.ToArray();
      }
      return bytes;
  }
  
  public static BitmapImage ToBitmapImage(this byte[] bytes, int width, int height)
  {
      BitmapImage bitmapImage = new BitmapImage();
      using (MemoryStream ms = new MemoryStream(bytes))
      {
          ms.Position = 0;
          bitmapImage.BeginInit();
          bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
          bitmapImage.StreamSource = ms;
          bitmapImage.EndInit(); // HERE'S AN EXCEPTION!!!
      }
      return bitmapImage;
  }
  </code></pre>
  
  <p>First one works fine, but when I try to convert from <code>byte[]</code> into <code>BitmapImage</code> I got a <code>NotSupportedException</code>... Why? How to correct the code of the 2nd method?</p>