Canvas: trying to draw too large(144609280bytes) b

2019-03-04 08:59发布

问题:

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

回答1:

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>);