title: BitmapImage.EndInit() throwing 'System.NotSupportedException'
body: <p>Here's my code:
  I fill the MemoryStream here, with this code.</p>
  
  <pre><code>private void treeView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
      {
          try
          {
              var a = treeView.SelectedItem as TreeViewItem;
  
              if (a.Header.ToString().EndsWith(".jpg"))
              {
                  Bitmap temp = new Bitmap(a.Tag.ToString());
  
                  try
                  {
                      OriginalImage.Dispose();  
                  }
                  catch { };
                  OriginalImage = new MemoryStream(); 
  
                  temp.Save(OriginalImage, ImageFormat.Bmp);                    
                  Uri path = new Uri(a.Tag.ToString());
                  actualImage.Source = new BitmapImage(path);
  
              }
          }
          catch { };
      }
  </code></pre>
  
  <p>Right after that block, this was suppose to happen, but on the "bitmap.EndInit()" I get the exception'System.NotSupportedException'.</p>
  
  <pre><code> var bitmap = new BitmapImage();                
   bitmap.BeginInit();
   bitmap.StreamSource = OriginalImage;
   bitmap.CacheOption = BitmapCacheOption.OnLoad;
   bitmap.EndInit();
   bitmap.Freeze();    
   actualImage.Source = bitmap;
  </code></pre>
  
  <p>Anyone has any idea of what might be causing that? Those methods were suppose to load a image in a System.Windows.Controls.Image and the second block is to return the loaded image to it's default values, before editing the picture.</p>
  
  <p>The NotSupportedException.StackTrace is:</p>
  
  <pre><code>"at System.Windows.Media.Imaging.BitmapDecoder.SetupDecoderFromUriOrStream(Uri uri, Stream stream, BitmapCacheOption cacheOption, Guid&amp; clsId, Boolean&amp; isOriginalWritable, Stream&amp; uriStream, UnmanagedMemoryStream&amp; unmanagedMemoryStream, SafeFileHandle&amp; safeFilehandle)\r\n   at System.Windows.Media.Imaging.BitmapDecoder.CreateFromUriOrStream(Uri baseUri, Uri uri, Stream stream, BitmapCreateOptions createOptions, BitmapCacheOption cacheOption, RequestCachePolicy uriCachePolicy, Boolean insertInDecoderCache)\r\n   at System.Windows.Media.Imaging.BitmapImage.FinalizeCreation()\r\n   at System.Windows.Media.Imaging.BitmapImage.EndInit()\r\n   at WpfApplication2.MainWindow.resetBtn_Click(Object sender, RoutedEventArgs e) in c:\\Users\\Albert Sato Damas\\Desktop\\ImageEditing - Copy - Copy\\WpfApplication2\\MainWindow.xaml.cs:line 270"
  </code></pre>