I'm trying to do a game in which i have to rotate a bitmap multiple times.But sometimes it shows Out Of Memory Error.How to solve this? Can anyone suggest me a way to recycle a bitmap or any other way out. This is the code I have written :
public void rotate() {
CustomImageView customImageView=this;
Bitmap bitmap = ((BitmapDrawable)customImageView.getDrawable()).getBitmap();
Matrix matrix = new Matrix();
matrix.setRotate(90, (float) bitmap.getWidth() / 2, (float) bitmap.getHeight() / 2);
try {
Bitmap b2 = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
if (bitmap != b2) {
bitmap.recycle();
bitmap = b2;
}
} catch (OutOfMemoryError ex) {
System.out.println("Exception::out of memory in customimage");
throw ex;
}
customImageView.setImageBitmap(bitmap);
}