Back to project page AndroidQuiz.
The source code is released under:
MIT License
If you think the Android project AndroidQuiz listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.bignerdranch.android.androidquiz; /*from w w w . j a v a2 s . c om*/ import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Matrix; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; public class ImageViewHelper { public ImageViewHelper() {} public enum ROTATION { VERTICAL, HORIZONTAL } public Bitmap flipImage(Bitmap src, ROTATION type) { // create new matrix for transformations Matrix matrix = new Matrix(); // if vertical if (type == ROTATION.VERTICAL) { // y = y * -1 matrix.preScale(1.0f, -1.0f); } // if horizonal else if (type == ROTATION.HORIZONTAL) { // x = x * -1 matrix.preScale(-1.0f, 1.0f); // unknown type } else { return null; } // return transformed image return Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true); } public static Bitmap drawableToBitmap (Drawable drawable) { if (drawable instanceof BitmapDrawable) { return ((BitmapDrawable)drawable).getBitmap(); } Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); drawable.draw(canvas); return bitmap; } }