Load image from url

前端 未结 16 2205
独厮守ぢ
独厮守ぢ 2020-11-22 05:12

I have an image URL. I want to display an image from this URL in an ImageView but I am unable to do that.

How can this be achieved?

16条回答
  •  梦如初夏
    2020-11-22 05:46

    There is two way :

    1) Using Glide library This is best way to load image from url because when you try to display same url in second time it will display from catch so improve app performance

    Glide.with(context).load("YourUrl").into(imageView);
    

    dependency : implementation 'com.github.bumptech.glide:glide:4.10.0'


    2) Using Stream. Here you want to create bitmap from url image

    URL url = new URL("YourUrl");
    Bitmap bitmap = BitmapFactory.decodeStream(url.openConnection().getInputStream());
    imageView.setImageBitmap(bitmap);
    

提交回复
热议问题