flip Bitmap - Android Graphics

Android examples for Graphics:Bitmap Transform

Description

flip Bitmap

Demo Code


//package com.java2s;

import android.graphics.Bitmap;

import android.graphics.Matrix;

public class Main {
    public static final int FLIP_HORIZONTAL = 0;
    public static final int FLIP_VERTICAL = 1;

    public static Bitmap flipBitmap(Bitmap image, int flipType) {
        Matrix matrix = new Matrix();

        if (flipType == FLIP_HORIZONTAL) {
            matrix.preScale(-1, 1);/*from w  w w .  j  a  va 2s . com*/
        } else if (flipType == FLIP_VERTICAL) {
            matrix.preScale(1, -1);
        } else {
            return image;
        }

        return Bitmap.createBitmap(image, 0, 0, image.getWidth(),
                image.getHeight(), matrix, false);
    }
}

Related Tutorials