Search code examples
androidpicasso

Picasso OutOfMemoryError:


  for (int i = 1; i <= content.getPptPageCount(); i++) {
                        final String thumbNailPath = ImageUtils.getThumbNailPathsForLocalContent(contentID, i);
                        final Bitmap bmp = Picasso.with(AppManagers.getAppContext().getContext())
                                .load(ProxyPathHandler.getProxyURLSlide(content.getPresentationFileID(), i))
                                .get();
                        ImageUtils.writeBitmapToFile(bmp, thumbNailPath);
                        thumbNailPathList.add(thumbNailPath);
                    }

While trying to get() bitmap from Picasso I am getting this error

Caused by: java.lang.OutOfMemoryError: Failed to allocate a 49486856 byte allocation with 16777216 free bytes and 31MB until OOM at dalvik.system.VMRuntime.newNonMovableArray(Native Method) ~[na:0.0] at android.graphics.BitmapFactory.nativeDecodeStream(Native Method) ~[na:0.0] at android.graphics.BitmapFactory.decodeStreamInternal(BitmapFactory.java:773) ~[na:0.0] at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:749) ~[na:0.0] at com.squareup.picasso.BitmapHunter.decodeStream(BitmapHunter.java:142) ~[na:0.0] at com.squareup.picasso.BitmapHunter.hunt(BitmapHunter.java:217) ~[na:0.0] at com.squareup.picasso.RequestCreator.get(RequestCreator.java:396) ~[na:0.0] at com.allego.android.app.manager.ContentManager$70.call(ContentManager.java:2969) ~[na:0.0] at com.allego.android.app.manager.ContentManager$70.call(ContentManager.java:2947) ~[na:0.0] at io.reactivex.internal.operators.single.SingleFromCallable.subscribeActual(SingleFromCallable.java:35) ~[na:0.0] at io.reactivex.Single.subscribe(Single.java:2702) ~[na:0.0] at io.reactivex.internal.operators.single.SingleSubscribeOn$SubscribeOnObserver.run(SingleSubscribeOn.java:89) ~[na:0.0] at io.reactivex.Scheduler$DisposeTask.run(Scheduler.java:451) ~[na:0.0] at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:61) ~[na:0.0]

I kinda can solve this by adding

 android:largeHeap="true"
 android:hardwareAccelerated="false"

But I would like to find another solution,thx in advance.


Solution

  • You need to load smaller images. If you are looking for thumbnails, you should have a service that scales the images to thumbnail sizes. Maybe 160x160 px and manage it that way. You are handling far too large of images.

    However, if you insist on using large images, you can at least allow Picassa to scale them for you or Glide.

    For example. Glide can do override size so you don't spend all the memory resource over drawing the pixels.

    Glide
     .with(context)
     .load(yourImageUrl)
     .override(200, 200)
     .into(imageView);
    

    Picassa will do the same thing.