rotate Bitmap Translate - Android Graphics

Android examples for Graphics:Bitmap Rotate

Description

rotate Bitmap Translate

Demo Code


//package com.java2s;

import android.graphics.Bitmap;

import android.graphics.Matrix;

public class Main {

    public static Bitmap rotateBitmapTranslate(Bitmap bitmap, float degrees) {
        Bitmap mBitmap = null;/* w  w  w.  j  a  v a2 s .  c  o m*/
        int width;
        int height;
        try {
            Matrix matrix = new Matrix();
            if ((degrees / 90) % 2 != 0) {
                width = bitmap.getWidth();
                height = bitmap.getHeight();
            } else {
                width = bitmap.getHeight();
                height = bitmap.getWidth();
            }
            int cx = width / 2;
            int cy = height / 2;
            matrix.preTranslate(-cx, -cy);
            matrix.postRotate(degrees);
            matrix.postTranslate(cx, cy);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return mBitmap;
    }
}

Related Tutorials