Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slow Loading big images with Picasso

I'm using Picasso to load JPGs of about 250-500 Kb (1600x~1200) from Url into ImageView.

Picasso.with(getApplicationContext())
.load(stringURL)                        
.placeholder(R.drawable.holder).error(R.drawable.holder)
.into(image)

My ImageView:

<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:layout_marginTop="0dip"
android:adjustViewBounds="true"
android:cropToPadding="false"
android:scaleType="fitCenter" 

/>;

The problem is that the first load of the image is very very slow (about 20 seconds), the cpu consumption is high, and so memory allocation. LogCat shows for example "Grow heap (frag case) to 56.789 for 7601812-byte allocation" for a single image.

Is something related to image caching? There's a way to disable caching and directly download original image into the ImageView?

Downloading the same images from an IPhone into a twin-app is instantaneous...

like image 279
Riccardo Seravalle Avatar asked Sep 30 '22 19:09

Riccardo Seravalle


2 Answers

If you use fit() or resize() that should fix your issue. I currently load hundreds of jpg files that are very large into a single GridLayout and have no problems.

like image 77
Lord Sidious Avatar answered Oct 05 '22 07:10

Lord Sidious


I switched to Volley. Loading the same images now take a fraction of the time.

like image 42
Riccardo Seravalle Avatar answered Oct 05 '22 06:10

Riccardo Seravalle