rotate Bitmap via Matrix - Android android.graphics

Android examples for android.graphics:Bitmap Operation

Description

rotate Bitmap via Matrix

Demo Code

import android.graphics.Bitmap;
import android.graphics.Matrix;

public class Main {

  /**//from  w w  w  .  jav  a 2s  .c o  m
   * rotate bitmap
   * 
   * @param source
   *          bitmap to rotate
   * @param rotation
   *          rotation in degrees
   * @return rotated bitmap
   */
  public static Bitmap rotateBitmap(Bitmap source, float rotation) {
    Matrix matrix = new Matrix();
    matrix.postRotate(rotation);
    Bitmap result = Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, false);
    return result;
  }

}

Related Tutorials