Load image from URL to imageView as well as Cache

12,066

Solution 1

for this you can use picasso Library You can download it from Picasso Library site simply put this jar file into libs folder. It will manage all property of Image. http://square.github.io/picasso/

String imgURL = "Your URL";
ivmage = (ImageView) findViewById(R.id.imageView1);
Picasso.with(MainActivity.this).load(imgURL).into(ivmage);

Solution 2

You can use Picasso Library.

By Using Picasso, The Advantages are

  • Handling ImageView recycling and download cancelation in an adapter.
  • Complex image transformations with minimal memory use.
  • Automatic memory and disk caching.

To load Image from Url

Picasso.with(context).load(url).into(imageView);

Refer this link for Api : Picasso

Solution 3

you can use Glide https://github.com/bumptech/glide

Glide.with(this).load("imageURl").into(imageView);

Solution 4

I suggest picasso library for doing this. here is the detailed documentation of picasso library.

ex:

Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView);

or you can make use of volley's ImageLoader. here you can find the documentation for Volley's image loading.

ex :

// Retrieves an image specified by the URL, displays it in the UI.
ImageRequest request = new ImageRequest(url,
    new Response.Listener<Bitmap>() {
        @Override
        public void onResponse(Bitmap bitmap) {
            mImageView.setImageBitmap(bitmap);
        }
    }, 0, 0, null,
    new Response.ErrorListener() {
        public void onErrorResponse(VolleyError error) {
            mImageView.setImageResource(R.drawable.image_load_error);
        }
    });
// Access the RequestQueue through your singleton class.
MySingleton.getInstance(this).addToRequestQueue(request);

if you are using volley. then you have to cache images manually. picasso will cache images by default.

Share:
12,066
patel
Author by

patel

Updated on July 18, 2022

Comments

  • patel
    patel almost 2 years

    Hi i am new beginner in android. I want to insert image in imageView from URL but whenever one time it is loaded from URL in imageView then second time it should be insert without internet means it would be stored in cache as well.

  • ehsan wwe
    ehsan wwe over 6 years
    thanx third party is best way