Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;

import android.graphics.Matrix;

public class Main {
    public static Bitmap getFlippedBitmap(Resources res, int resId) {

        BitmapFactory.Options opt = new BitmapFactory.Options();
        opt.inJustDecodeBounds = true;
        //Below line is necessary to fill in opt.outWidth, opt.outHeight
        Bitmap b = BitmapFactory.decodeResource(res, resId, opt);

        b = Bitmap.createBitmap(opt.outWidth, opt.outHeight, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(b);

        Matrix flipHorizontalMatrix = new Matrix();
        flipHorizontalMatrix.setScale(-1, 1);
        flipHorizontalMatrix.postTranslate(b.getWidth(), 0);

        Bitmap bb = BitmapFactory.decodeResource(res, resId);
        canvas.drawBitmap(bb, flipHorizontalMatrix, null);

        return b;
    }
}