Rotates a bitmap by a specified amount. - Android Graphics

Android examples for Graphics:Bitmap Rotate

Description

Rotates a bitmap by a specified amount.

Demo Code


//package com.java2s;

import android.graphics.Bitmap;

import android.graphics.Matrix;

public class Main {
    /**// w w  w  .  jav a  2  s .c  o m
     * Rotates a bitmap by a specified amount.
     * @param bitmap the bitmap to be rotated
     * @param rotationFactor the amount in degrees to rotate
     * @return the rotated bitmap
     */
    public static Bitmap rotateBitmap(Bitmap bitmap, float rotationFactor) {
        Matrix rotationMatrix = new Matrix();
        rotationMatrix.postRotate(rotationFactor);

        return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(),
                bitmap.getHeight(), rotationMatrix, true);
    }
}

Related Tutorials