我正在开发一个Android应用程序,使用位图将图像绑定到ImageView上。我的要求是旋转ImageView并给它加上边框。我已经成功实现了这个功能,但是当应用程序使用此活动两三次后,会出现“强制关闭”错误,显示位图超出VM内存。请帮助我在代码中减少位图内存消耗,并让我知道如何修改代码以实现相同的功能?
final int BORDER_WIDTH = 5;
// Set the border color
final int BORDER_COLOR = Color.WHITE;
Bitmap res = Bitmap.createBitmap(CAPTURE_IMAGE.getWidth() + 2
* BORDER_WIDTH, CAPTURE_IMAGE.getHeight() + 2 * BORDER_WIDTH,
CAPTURE_IMAGE.getConfig());
System.gc();
Canvas canvas = new Canvas(res);
Paint paint = new Paint();
paint.setColor(BORDER_COLOR);
canvas.drawRect(0, 0, res.getWidth(), res.getHeight(), paint);
canvas.drawBitmap(CAPTURE_IMAGE, BORDER_WIDTH, BORDER_WIDTH, paint);
Matrix mat = new Matrix();
// Set the Imageview position
mat.postRotate(355);
bMapRotate = Bitmap.createBitmap(res, 0, 0, res.getWidth(),
res.getHeight(), mat, true);
System.gc();
res.recycle();
res = null;
paint = null;
canvas = null;
mat = null;
// Set the captured bitmap image in the imageview
mShareImageView.setImageBitmap(bMapRotate);