Android How to - Rotate Image








Question

We would like to know how to rotate Image.

Answer

// w  w  w .j a v a 2 s .co  m
import android.graphics.Bitmap;
import android.graphics.Matrix;
public class Main {

  public static Bitmap rotateImageView(int angle, Bitmap bitmap) {

    if (bitmap == null)
      return null;

    Matrix matrix = new Matrix();
    matrix.postRotate(angle);

    Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(),
        bitmap.getHeight(), matrix, true);
    if (bitmap != null && !bitmap.isRecycled()) {
      bitmap = null;
    }
    // bitmap.recycle();
    return resizedBitmap;
  }

}