private static Bitmap getScaledBitmap(Bitmap bitmap, RelativeLayout
relativeLayout, Context context) {
try {
Bitmap background =
Bitmap.createBitmap((int) relativeLayout.getWidth(), (int)
relativeLayout.getHeight(), Bitmap.Config.ARGB_8888);
float
originalWidth = bitmap.getWidth(), originalHeight =
bitmap.getHeight();
Canvas canvas = new Canvas(background);
float
scale = relativeLayout.getWidth() / originalWidth;
float xTranslation
= 0.0f, yTranslation = (relativeLayout.getHeight() - originalHeight * scale) / 2.0f;
Matrix transformation = new Matrix();
transformation.postTranslate(xTranslation, yTranslation);
transformation.preScale(scale, scale);
Paint paint = new Paint();
paint.setFilterBitmap(true);
canvas.drawBitmap(bitmap,
transformation, paint);
try {
RenderScript rs =
RenderScript.create(context);
Allocation inputAlloc =
Allocation.createFromBitmap(rs, background);
ScriptIntrinsicBlur blur
= ScriptIntrinsicBlur.create(rs, inputAlloc.getElement());
blur.setRadius(25);
blur.setInput(inputAlloc);
Bitmap blurredBitmap =
Bitmap.createBitmap(background.getWidth(), background.getHeight(),
background.getConfig());
Allocation outAlloc =
Allocation.createFromBitmap(rs, blurredBitmap);
blur.forEach(outAlloc);
outAlloc.copyTo(blurredBitmap);
rs.destroy();
return blurredBitmap;
} catch (Exception e) {
L.e("getScaledBitmap:
RenderScript:" + e); return background; } } catch(Exception e) {
L.e("getScaledBitmap: " + e);
} return bitmap;
}
//错误引起:
java.lang.OutOfMemoryError at
android.graphics.BitmapFactory.nativeDecodeStream(Native Method) at
android.graphics.BitmapFactory.decodeStreamInternal(BitmapFactory.java:613)
at
android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:589)
at
android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:627)
at
net.databeat.android.imsmediaplayer.player.utils.ImageLoadTask.doInBackground(ImageLoadTask.java:
75)
at
net.databeat.android.imsmediaplayer.player.utils.ImageLoadTask.doInBackground(ImageLoadTask.java:
31)
List item
答案 0 :(得分:0)
您可以通过为java
指定Xmx参数来增加虚拟机分配的内存java -Xmx2048m