Start a Project

Picasso Library Use for Image Loading in Android

What is Picasso Library?

A powerful image downloading and caching Library for Android. By its use Developer, to load an image in “android application” with one line of code, without worry about caching, transformation and threading an image to load.

 

Syntax:

 

where “this” is  Activity object, “url” is image address URL (source) and “imageview” is ImageView (destination).

Picasso methods –

  1. resize(width, height), use for resizing an image.
  2. onlyScaleDown(), use with resize() method when small image not to resize.
  3. centerInside(), use for, when an image not  fills the bounds of ImageView.
  4. fit(), when ImageView is well defined in size then  it resizes the image to ImageView width and height.
  5. centerInCrop(), use for, when an image fills the bounds of ImageView.

memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE) ,

NO_CACHE- Skips memory cache lookup when processing a request.

NO_STORE- Skips storing the final result into the memory cache. Useful for one-off requests to avoid evicting other bitmaps from the cache (it is needed, when loads an image only once).

 

Out of memory Exception :     It happened when loading large size images . So, it solved by resizing the images. if we use resize(width, height) then the image is not resized as the aspect ratio. So we use a custom transform class using transform() method.

Example.

 

 

Exit mobile version