A.AL
A.AL

Reputation: 145

Loading large images using Picasso

Im trying to load large images using Picasso

public static final int MAX_WIDTH= 500;
public static final int MAX_HEIGHT= 500;

 Picasso.with(imageView.getContext())
                .load(Utils.imagePath(list.get(position).getImage()))
                .resize(MAX_WIDTH,MAX_HEIGHT)
                .onlyScaleDown()
                .memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE)
                .into(imageView);

but i'm getting Fatal Exception: java.lang.OutOfMemoryError for above code, the images i'm trying to load are exactly like the images below

enter image description here

Should i resize the image from backend or there is something i can do to avoid this? Any help would be greatly appreciated.

Upvotes: 1

Views: 1015

Answers (2)

Bhuvanesh BS
Bhuvanesh BS

Reputation: 13627

Try large heap. Insert android:largeheap="true" in your manifest file

<application
    android:name=".MyApplication"
    .....
    .....
    android:largeHeap="true"
    .....
    .....
    android:theme="@style/AppTheme" >
</application>

Also, it's better to either use .fit().

.fit() - This will result in the delayed execution of the request until the ImageView has been laid out.

Upvotes: 1

smora
smora

Reputation: 719

Having this in your adapter (seems to be), image load can be call many times, because of adapter multiple bindviews.

So are you sure about

.memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE)

?

You'd better define a memory policy, maybe with short memory size, or short timeout if you don't want to store too much data.

Upvotes: 0

Related Questions