Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 925
user3593643 Avatar asked May 25 '14 22:05

user3593643


1 Answers

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);
like image 81
Jason Avatar answered Oct 06 '22 11:10

Jason