I work in an Android application and I use a bitmap to snap the image to an ImageView. My requirement is to rotate this ImageView and provide a border to this ImageView. I have successfully implemented this, but after the application uses this activity two to three times, the message "force close" appears, talking about the Bitmap from the VM memory. Please help me minimize the memory consumption of the bitmap in my code. And let me know how to change the code for the same?
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);
source share