1

I am getting Out of memory error while running my project. I understand this error because of large background images in the project. I came across some articles to scale down an image and then load them. How can I scale down all the images and load them efficiently in the project.

2 Answers2

1

Picasso is a great library for handling images for Android.

http://square.github.io/picasso/

Loading an image for a specific size and can easy like this:

Picasso.with(context)
  .load(url)
  .resize(50, 50)
  .centerCrop()
  .into(imageView)

If you are truly showing alot of images, consider setting android:hardwareAccelerated="true"

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="foo.bar"
    android:hardwareAccelerated="true">
...
</manifest>
liloargana
  • 165
  • 1
  • 10
0

To reduce the size of images change the inSampleSize of each image. If inSampleSize is set to a value > 1 then the decoder subsamples the original image and returns you a smaller image to save memory. inSampleSize can be found in BitmapFactory.Options

Go to the following link for more details on this :-

http://developer.android.com/training/displaying-bitmaps/load-bitmap.html

If your images still lags you can scale them down further by help of Bitmap.createScaledBitmap(Bitmap src, int dstWidth, int dstHeight, boolean filter) method.

Varun Kumar
  • 1,241
  • 1
  • 9
  • 18