user3593643 user3593643 - 2 months ago 63
Android Question

Load image from url to ImageView - C#

I want to load an image from url to imageview in c# ( android programming ) after search in google i cant find any good result , thank you for helping

i am using xamarin studio

Answer

The very first hit I got from Google was a thread on the Xamarin forums discussing this exact issue:

private Bitmap GetImageBitmapFromUrl(string url)
{
     Bitmap imageBitmap = null;

     using (var webClient = new WebClient())
     {
          var imageBytes = webClient.DownloadData(url);
          if (imageBytes != null && imageBytes.Length > 0)
          {
               imageBitmap = BitmapFactory.DecodeByteArray(imageBytes, 0, imageBytes.Length);
          }
     }

     return imageBitmap;
}

var imageBitmap = GetImageBitmapFromUrl("http://xamarin.com/resources/design/home/devices.png");
imagen.SetImageBitmap(imageBitmap);