6
votes

I am loading image to image-view from JSon. JSon only bring the path of image URL. I am setting the value using picasso. but it gives error for some image and for rest it is working fine.

Picasso.with(context).load(rowItem.getProductImages().get(0)).into(holder.productImageView);

error is :

 2771-2793/com.koove E/art﹕ Throwing OutOfMemoryError "Failed to allocate a 31961100 byte allocation with 4194304 free bytes and 27MB until OOM"
03-25 09:53:23.666    2771-2793/com.koove D/skia﹕ --- decoder->decode returned false
1
You need to download the images in the background, then resize them (or make a copy of one) to the screen size / presentation size (again in the background) then display them.Tigger

1 Answers

4
votes

You should use the method fit() in Picasso, it's measuring the dimensions of the target ImageView and internally uses resize() to reduce the image size to the dimensions of the ImageView.

The advantage is that the image is at the lowest possible resolution, without affecting its quality. A lower resolution means less data to be hold in the cache.

Picasso.with(context).load(rowItem.getProductImages().get(0)).fit().into(holder.productImageView);

If you still have the OOM, remove the cache using the memory policy.

Picasso.with(context).load(rowItem.getProductImages().get(0)).memoryPolicy(MemoryPolicy.NO_CACHE).fit().into(holder.productImageView);