Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Canvas: trying to draw too large(144609280bytes) bitmap, at android.view.DisplayListCanvas.throwIfCannotDraw

I get image from a web service, i do following to display it in imageView.

Picasso.with(getApplicationContext()).load(imageURL).fit().centerCrop().into(ivNews);

2 days ago a 2048X1600 resolution images was uploaded on server, and all of sudden app start crashing with this exception Canvas: trying to draw too large(144609280bytes) bitmap

There is a possibility that the image uploaded on server was higher than the mentioned resolution, and server can upload more high resolution images in future as well.

I read this article, Its mentioned that glide is faster and better than picasso in terms of performance,

It also mentioned that if you use, .fit().centerCrop() then the performance is better, but i was already using these, and got these error message

I want to solve this by using picasso

like image 875
dev90 Avatar asked Feb 19 '18 09:02

dev90


1 Answers

You could use scaleDown() to scale the image if it is of bigger size. You could use it like below.

Picasso  
.with(context)
.load(<image_url>)
.resize(2048, 1600)
.onlyScaleDown() // the image will only be resized if it's bigger than 2048x 1600 pixels.
.into(<image_view>);
like image 79
SripadRaj Avatar answered Oct 22 '22 17:10

SripadRaj