How to load a image from url, imageView.SetImageURI not working?

var image = new ImageView(this);
var uri = Android.Net.Uri.Parse(word);
image.SetImageURI(uri);

Where word is a url with a image like www.something.com/goku.png

And im getting [System.out] resolveUri failed on bad bitmap uri:

Is there other way to do that or am i doing this wrong?

Posts

  • HumaylHumayl AEMember ✭✭

    When you give your imageView the internet url .
    use below
    var imageBitmap =Common.GetBitmapFromUrl(mItems[position].PhotoUrlPassport);
    imgPic.SetImageBitmap(imageBitmap);

    public static Android.Graphics.Bitmap GetBitmapFromUrl(string url)
    {
    using (WebClient webClient = new WebClient())
    {
    byte[] bytes = webClient.DownloadData(url);
    if (bytes != null && bytes.Length > 0)
    {
    return Android.Graphics.BitmapFactory.DecodeByteArray(bytes, 0, bytes.Length);
    }
    }
    return null;
    }

  • teoman-shipahiteoman-shipahi USMember ✭✭

    @Humayl works great! thanks.

  • gabooboogabooboo USMember ✭✭

    @Humayl said:
    When you give your imageView the internet url .
    use below
    var imageBitmap =Common.GetBitmapFromUrl(mItems[position].PhotoUrlPassport);
    imgPic.SetImageBitmap(imageBitmap);

    public static Android.Graphics.Bitmap GetBitmapFromUrl(string url)
    {
    using (WebClient webClient = new WebClient())
    {
    byte[] bytes = webClient.DownloadData(url);
    if (bytes != null && bytes.Length > 0)
    {
    return Android.Graphics.BitmapFactory.DecodeByteArray(bytes, 0, bytes.Length);
    }
    }
    return null;
    }

    Thanks @Humayl your solution works fine for me.

  • BerayBentesenBerayBentesen TRUniversity ✭✭✭✭

    @gabooboo solution works, but it is not good solution. Use Glide for any image downloading process. It's just one line and takes care of everything.

  • gabooboogabooboo USMember ✭✭

    @BerayBentesen said:
    @gabooboo solution works, but it is not good solution. Use Glide for any image downloading process. It's just one line and takes care of everything.

    Thanks ;)

Sign In or Register to comment.