title: Metro APP - BitmapImage to Byte[] or Download Image from Web and convert it to a Byte[] Array
body: <p>Is there a way to convert a BitmapImage (Windows.UI.Xaml.Media.BitmapImage) to an Byte[] Array? Nothing I've tried work....
  Another possible scenario (if BitmapImage cannot be converted to Byte array) is to download the image from web and then convert it to an array...</p>
  
  <p>But I don't know how I can do that...
  It would be really nice, if someone have an idea.</p>
  
  <p>Current try:</p>
  
  <pre><code>        HttpClient http = new HttpClient();
          Stream resp = await http.GetStreamAsync("http://localhost/img/test.jpg");
  
          var ras = new InMemoryRandomAccessStream();
          await resp.CopyToAsync(ras.AsStreamForWrite());
  
          BitmapImage bi = new BitmapImage();
          bi.SetSource(ras);
  
  
          byte[] pixeBuffer = null;
  
          using (MemoryStream ms = new MemoryStream())
          {
              int i = bi.PixelHeight;
              int i2 = bi.PixelWidth;
              WriteableBitmap wb = new WriteableBitmap(bi.PixelWidth, bi.PixelHeight);
  
              Stream s1 = wb.PixelBuffer.AsStream();
              s1.CopyTo(ms);
  
              pixeBuffer = ms.ToArray();
          }
  </code></pre>
  
  <p>But it doesn't work... i &amp; i2 are always set to 0. So ras doesn't work correctly.... What's going on?</p>
  
  <p>Thanks</p>