Rotates a Bitmap by angle degrees - Android Graphics

Android examples for Graphics:Bitmap Rotate

Description

Rotates a Bitmap by angle degrees

Demo Code


//package com.java2s;

import android.graphics.Bitmap;

import android.graphics.Matrix;

public class Main {
    /**// w  w  w  .  j  a  va2 s .co m
     * Rotates a <code>Bitmap</code> by <code>angle</code> degrees
     * 
     * @param original Bitmap to rotate
     * @param angle Angle to rotate
     * @return Rotated Bitmap
     */
    public static Bitmap getRotatedFor(Bitmap original, int angle) {
        int w = original.getWidth();
        int h = original.getHeight();

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

        return Bitmap.createBitmap(original, 0, 0, w, h, mtx, true);
    }
}

Related Tutorials