title: C# Load JPG file, extract BitmapImage
body: <p>I am trying to extract a BitmapImage from a JPG. This is the code I have:</p>
  
  <pre><code>FileStream fIn = new FileStream(sourceFileName, FileMode.Open); // source JPG
  Bitmap dImg = new Bitmap(fIn);
  MemoryStream ms = new MemoryStream();
  dImg.Save(ms, ImageFormat.Jpeg);
  image = new BitmapImage();
  image.BeginInit();
  image.StreamSource = new MemoryStream(ms.ToArray());
  image.EndInit();
  ms.Close();
  </code></pre>
  
  <p>image comes back with a 0 × 0 image, which of course means it didn't work. How do I do this?</p>