title: How to download images Asynchronously
body: <p>I'm using this method to download an array of images synchronously from the server</p>
  
  <pre><code>Bitmap GetImageBitmapFromUrl(string url)
  {
      Bitmap imageBitmap = null;
      try
      {
          using (var webClient = new WebClient())
          {
              var imageBytes = webClient.DownloadData(url);
              if (imageBytes != null &amp;&amp; imageBytes.Length &gt; 0)
              {
                  imageBitmap = BitmapFactory.DecodeByteArray(imageBytes, 0, imageBytes.Length);
              }
          }
      }
      catch
      {
          //Silence is gold.
      }
      displayPic();
      return imageBitmap;
  }
  </code></pre>
  
  <p>But I want now to use this method Asynchronously. I changed it to look like this</p>
  
  <pre><code>async Task&lt;Bitmap&gt; GetImageBitmapFromUrl(string url)
  {
      Bitmap imageBitmap = null;
      try
      {
          using (var webClient = new WebClient())
          {
              var imageBytes = await webClient.DownloadStringTaskAsync(url);
              if (imageBytes != null &amp;&amp; imageBytes.Length &gt; 0)
              {
                  //imageBitmap = BitmapFactory.DecodeByteArray(Encoding.ASCII.GetBytes(imageBytes), 0, imageBytes.Length);
                  imageBitmap = BitmapFactory.DecodeByteArray(Encoding.BigEndianUnicode.GetBytes(imageBytes), 0, imageBytes.Length);
              }
          }
      }
      catch
      {
          //Silence is gold.
      }
      displayPic();
      return imageBitmap;
  }
  </code></pre>
  
  <p>But the conversion from string to byte array didn't work and I'm recieving a <code>null</code> object from the method every time.</p>
  
  <p>What is the problem that causes making the <code>imageBitmap</code> variable become <code>null</code> in the second method? How can I solve that?</p>