Skip to content Skip to sidebar Skip to footer

Picasso Gives Out Of Memory When Load An Image

I am using Picasso to load images from my server and display them in ImageView. I observes some crash reports from user's phone where Out of Memory Exception happens when Picasso i

Solution 1:

To load small images like icons o launchers we can use .setImageResource(image) However, to load big images is better to use Picasso and get the benefit of simplicity and local caching.

It is necesary to setup Picasso properly according to the documentation:

"Be sure to use fit() to resize the image before loading into the ImageView. Otherwise, you will consume extra memory, experience sluggish scrolling, or encounter out of memory issues if you render a lot of pictures".

if (imageUri != null && !imageUri.isEmpty()) {
   Picasso.with(context).load(imageUri)
  .fit().centerCrop()
  .placeholder(R.drawable.user_placeholder)
  .error(R.drawable.user_placeholder_error)
  .into(imageView);
}

Solution 2:

Post a Comment for "Picasso Gives Out Of Memory When Load An Image"