Thursday, February 7, 2013
decodes image and scales bitmap it to reduce memory consumption
/** decodes image and scales it to reduce memory consumption **/
public static Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth) {
int width = bm.getWidth();
int height = bm.getHeight();
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
// CREATE A MATRIX FOR THE MANIPULATION
Matrix matrix = new Matrix();
// RESIZE THE BIT MAP
matrix.postScale(scaleWidth, scaleHeight);
// RECREATE THE NEW BITMAP
System.gc();
Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height,
matrix, false);
bm.recycle();
System.gc();
bm = null;
return resizedBitmap;
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment