Reputation: 97
I am taking the image from internal memory.and pasting it on the greator image in the merge function.after the 66 image the app is crashing badly and the error is out of memory . Do you have any idea why the app crashing and how to solve it.here the app crashes after image no 66 come`
public void mergeImageClicked(View v) {
int noOfImage = listFile.length;
Bitmap[] bitmap = new Bitmap[noOfImage];
Bitmap[] resizedBitmap = new Bitmap[noOfImage];
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
for (int j = 0; j < listFile.length; j++) {
bitmap[j] = BitmapFactory.decodeFile(listFile[j].getAbsolutePath(), options);
resizedBitmap[j] = ThumbnailUtils.extractThumbnail(bitmap[j], 30, 30);
}
`
Upvotes: 0
Views: 91
Reputation: 2372
You have limited memory per app on Android. Look into heap size and memory management here.
In you code, you seem to be be decoding the Bitmap and then holding into memory, this is bad practise - as you will always run out of memory sooner or later.
Its best to keep only the Bitmap you require, and then release when you have no need for it. Take a look at this on how to manage Bitmaps
Upvotes: 1
Reputation: 28516
You are keeping huge number of full sized bitmaps in your bitmap array. Instead you should keep only one bitmap for loading and resizing.
public void mergeImageClicked(View v) {
int noOfImage = listFile.length;
Bitmap[] resizedBitmap = new Bitmap[noOfImage];
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
for (int j = 0; j < listFile.length; j++) {
Bitmap bitmap = BitmapFactory.decodeFile(listFile[j].getAbsolutePath(), options);
resizedBitmap[j] = ThumbnailUtils.extractThumbnail(bitmap, 30, 30);
}
Upvotes: 3