reversal Bitmap by direction - Android Graphics

Android examples for Graphics:Bitmap Orientation

Description

reversal Bitmap by direction

Demo Code


//package com.java2s;

import android.graphics.Bitmap;

import android.graphics.Matrix;

public class Main {
    public static final int ROTATE_LEFT_RIGHT = 2;
    public static final int ROTATE_UP_DOWN = 3;

    public static Bitmap reversalBitmap(Bitmap bm, int direction) {
        Bitmap returnBm;//from  w w w .  j  a v a2  s  .c o  m
        Bitmap btt;
        Matrix mx = new Matrix();
        int w = bm.getWidth();
        int h = bm.getHeight();

        // ?????
        if (direction == ROTATE_LEFT_RIGHT) {
            mx.setScale(1, -1);
        } else if (direction == ROTATE_UP_DOWN) {
            mx.setScale(-1, 1);
        }

        btt = Bitmap.createBitmap(bm, 0, 0, w, h, mx, true);
        mx.setRotate(180);
        returnBm = Bitmap.createBitmap(btt, 0, 0, btt.getWidth(),
                btt.getHeight(), mx, true);

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

        return returnBm;
    }
}

Related Tutorials