Hopefully fixed OOM when bluring an image.
This commit is contained in:
parent
8ba3ed3b4b
commit
bfa800bce6
5 changed files with 34 additions and 19 deletions
|
|
@ -6,7 +6,9 @@ import android.content.Context;
|
|||
import android.content.res.ColorStateList;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
|
|
@ -247,4 +249,18 @@ public class Util {
|
|||
return config.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
|
||||
} else return false;
|
||||
}
|
||||
|
||||
public static Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth, boolean recycleOld) {
|
||||
int width = bm.getWidth();
|
||||
int height = bm.getHeight();
|
||||
float scaleWidth = ((float) newWidth) / width;
|
||||
float scaleHeight = ((float) newHeight) / height;
|
||||
Matrix matrix = new Matrix();
|
||||
matrix.postScale(scaleWidth, scaleHeight);
|
||||
Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);
|
||||
if (recycleOld && resizedBitmap != bm) {
|
||||
bm.recycle();
|
||||
}
|
||||
return resizedBitmap;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue