Java tutorial
//package com.java2s; import android.graphics.Bitmap; import android.graphics.Matrix; import android.util.Log; public class Main { private static final String TAG = "TransformationUtils"; /** * This is an expensive operation that copies the image in place with the pixels rotated. * If possible rather use getOrientationMatrix, and set that as the imageMatrix on an ImageView. * * @param imageToOrient Image Bitmap to orient. * @param degreesToRotate number of degrees to rotate the image by. If zero the original image is returned unmodified. * @return The oriented bitmap. May be the imageToOrient without modification, or a new Bitmap. */ public static Bitmap rotateImage(Bitmap imageToOrient, int degreesToRotate) { try { if (degreesToRotate != 0) { Matrix matrix = new Matrix(); matrix.setRotate(degreesToRotate); imageToOrient = Bitmap.createBitmap(imageToOrient, 0, 0, imageToOrient.getWidth(), imageToOrient.getHeight(), matrix, true); } } catch (Exception e) { if (Log.isLoggable(TAG, Log.ERROR)) { Log.e(TAG, "Exception when trying to orient image", e); } e.printStackTrace(); } return imageToOrient; } }