java – How to view images from url efficiently-ThrowExceptions

Exception or error:

What is the proper way to view images using a url efficiently( in case of memory)?

I know we can use both Bitmap and Drawable methods to access the image. But which method is more efficient in terms of memory?

Is there any code which make the methods mentioned above work in an efficient way?

How to solve:

You can use various image loader library for this purpose. The images loading library will handle all the issues related to image,memory caching for image,asyn task and all that.

1.)http://square.github.io/picasso/

This is an very efficient library to load images from URL. you have to write only one line code to perform all your work.

Picasso.with(context)
    .load(url)
    .placeholder(R.drawable.user_placeholder)
    .error(R.drawable.user_placeholder_error)
    .into(imageView);

2.)https://github.com/koush/ion

Here is another library for the same purpose

Ion.with((ImageView) viewImage)
                     .resize(96, 96)
                     .centerInside()
                     .load(url);

You can find so many other library for this purpose:
Universal image loader library etc..

You have to just include these library into your project and you can do your work by few lines of code..

Leave a Reply

Your email address will not be published. Required fields are marked *