Load Image from Web into ImageView

I've seen so many people havin Problems with loading a Image from Web directly into a Image View so i am going to share my solution:

`
private Android.Graphics.Bitmap GetImageBitmapFromUrl(Uri url) // or use a string here
{
Android.Graphics.Bitmap imageBitmap = null;

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

        return imageBitmap;
    }

`
Use this Function to download the Bitmap and use it just like this:

yourImageView.SetImageBitmap(GetImageBitmapFromUrl(URL HERE));

Posts

  • JasonAwbreyJasonAwbrey USInsider, University, Developer Group Leader mod

    Why is this posted in Xamarin.Forms?

Sign In or Register to comment.