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
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With