I think you are getting a lot of Bitmaps which overloads your system memory, or if it a single one a think it's an extremely huge one, So, to solve the problem, you have to do two things, first make sure you don't run this method a lot of times for the same Bitmap
(as that leads to a lot of Bitmaps stored in your memory and all of them belonging to the same one), second use a custom method to scale your Bitmaps in order to lower it's size and hence it's memory occupation area:
// to scale your Bitmaps
// assign newWidth and newHeight with the corresponding width and height that doesn't make your memory overloads and in the same time doesn't make your image loses it's Features
public static Bitmap scaleBitmap(Bitmap bitmapToScale, float newWidth, float newHeight) {
if(bitmapToScale == null)
return null;
//get the original width and height
int width = bitmapToScale.getWidth();
int height = bitmapToScale.getHeight();
// create a matrix for the manipulation
Matrix matrix = new Matrix();
// resize the bit map
matrix.postScale(newWidth / width, newHeight / height);
// recreate the new Bitmap and set it back
return Bitmap.createBitmap(bitmapToScale, 0, 0, bitmapToScale.getWidth(), bitmapToScale.getHeight(), matrix, true);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…