title: convert array of bytes to bitmapimage
body: <p>I'm going to convert array of bytes to <code>System.Windows.Media.Imaging.BitmapImage</code> and show the <code>BitmapImage</code> in an image control. </p>
  
  <p>When I'm using the first code, noting happens! no error and no image is displayed. But when I'm using the second one it works fine! can anyone say what is going on?</p>
  
  <p>first code is here:</p>
  
  <pre><code>public BitmapImage ToImage(byte[] array)
  {
     using (System.IO.MemoryStream ms = new System.IO.MemoryStream(array))
     {
         BitmapImage image = new BitmapImage();
         image.BeginInit();
         image.StreamSource = ms;
         image.EndInit();
         return image;
     }
  }
  </code></pre>
  
  <p>second code is here:</p>
  
  <pre><code>public BitmapImage ToImage(byte[] array)
  {
     BitmapImage image = new BitmapImage();
     image.BeginInit();
     image.StreamSource = new System.IO.MemoryStream(array);
     image.EndInit();
     return image;
   }
  </code></pre>