Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.graphics.Bitmap;

import android.graphics.Matrix;

public class Main {
    public static final int ROTATE_LEFT = 0;
    public static final int ROTATE_RIGHT = 1;

    public static Bitmap rotateBitmap(Bitmap bm, int direction) {
        Bitmap returnBm;
        int w = bm.getWidth();
        int h = bm.getHeight();

        Matrix matrix = new Matrix();
        if (direction == ROTATE_LEFT) {
            matrix.postRotate(-90);
        } else if (direction == ROTATE_RIGHT) {
            matrix.postRotate(90);
        }

        returnBm = Bitmap.createBitmap(bm, 0, 0, w, h, matrix, true);

        if (bm != returnBm) {
            bm.recycle();
        }

        return returnBm;
    }
}