Question

Using this code:

Picasso.with(context).load(url).resize(60, 60)

Does Picasso resize the image before it is downloaded? If the image was 8MB - I wouldn't want it to be downloaded then resized.

I couldnt find the answer anywhere but maybe it is obvious!

Was it helpful?

Solution

No, obviously it doesn't resize it before downloading - it's impossible. Look at the chaining, first - download, second - resizing. If you want to get a smaller images, you should ask for a smaller images if you have such a chance, of course. You can write graceful degradation: if the file size is bigger than limit, then just don't download it and display some placeholder instead. It can be implemented by checking content length at first:

URL url = new URL("http://server.com/file.png");
URLConnection urlConnection = url.openConnection();
urlConnection.connect();
int file_size = urlConnection.getContentLength();

Taken from here How to know the size of a file before downloading it?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top