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.
-
http://stackoverflow.com/questions/477572/strange-out-of-memory-issue-while-loading-an-image-to-a-bitmap-object – IntelliJ Amiya Nov 24 '15 at 12:57
-
Probably you can have a look into this article http://stackoverflow.com/a/8497703/2793134 – Nitin Mesta Nov 24 '15 at 12:59
2 Answers
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>

- 165
- 1
- 10
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.

- 1,241
- 1
- 9
- 18