0

I have an activity in which I use 2 resources:

1 round image, like this:

String image = dataSnapshot.child("thumb_image").getValue().toString();
Picasso.with(pilotProfileImage.getContext()).load(image)
    .placeholder(R.drawable.pilot_default).into(pilotProfileImage);

When thumb_image is a picture stored in Firebase Storage.

Another resource:

mImage.setBackgroundResource(R.drawable.m_air);

While R.drawable.m_air is a drawable saved in my drawable folder

I'm receiving

java.lang.OutOfMemoryError: Failed to allocate a 14745612 byte allocation with 10530520 free bytes and 10MB until OOM

I've seen solution with Bitmap but I'm not using bitmap here.

I've tried

mDroneImage.setImageBitmap(decodeSampledBitmapFromResource(getResources(), R.drawable.mavic_air, 100, 100))

In this solution: Strange out of memory issue while loading an image to a Bitmap object

but the app still crashes. In addition it doesn't solve the firebase image problem.

How can I solve it?

Edit: Found answers for the firebase problem in the docs: https://github.com/codepath/android_guides/wiki/Displaying-Images-with-the-Picasso-Library

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
jonb
  • 845
  • 1
  • 13
  • 36
  • what is the image resolution? – Ganesh Gudghe Mar 10 '18 at 11:38
  • The firebase' picture: 2400*2400 jpg , the drawable: 640*640 png – jonb Mar 10 '18 at 11:40
  • Ok I used: Picasso.with(pilotProfileImage.getContext()).load(image) .fit().placeholder(R.drawable.pilot_default).into(pilotProfileImage); Added the fit(), And also reduced the sizes of the placeholder - pilot_default to smaller then 500dx, and it fixed the problem. Another thing could be done is reduce the size of the drawable pictures, but currently it works without it – jonb Mar 10 '18 at 12:00
  • 2
    This is a non related firebase storage problem. You were trying to fit a huge image in memory. – Spiros I. Economakis Mar 10 '18 at 13:47

1 Answers1

1

If you're loading a 2400x2400 pixel image, you're loading about 16MB of data. The process you're currently using, loads all the data in memory in order to display it. Apparently the phone you're trying to run this code on doesn't have that amount of memory available.

There is a great piece of Picasso documentation on dealing with OutOfMemory errors while loading an image. Some of these approaches resize the image to reduce memory usage, so those should be a way for you to reduce memory usage.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Thanks for the details, I understand it better now. I solved the problem with Picasso documentation :) – jonb Mar 10 '18 at 17:13