Here you can find the source of manageBitmapRotatio(int photoW, int photoH, Bitmap bitMap, int rotation)
public static Bitmap manageBitmapRotatio(int photoW, int photoH, Bitmap bitMap, int rotation)
import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import android.content.Context; import android.graphics.Bitmap; import android.graphics.Bitmap.Config; import android.graphics.Canvas; import android.graphics.Matrix; import android.graphics.Paint; import android.graphics.PorterDuff.Mode; import android.graphics.PorterDuffXfermode; import android.graphics.Rect; import android.graphics.RectF; import android.media.ExifInterface; import com.audiosnaps.BaseActivity; import com.audiosnaps.log.MyLog; public class Main{ private static final String TAG = "BitmapUtil"; public static Bitmap manageBitmapRotatio(int photoW, int photoH, Bitmap bitMap, int rotation) { /********************************** * EXIF ORIENTATIONS 0: UNDEFINED 1: NORMAL 2: FLIP HORIZONTAL 3: ROTATE * 180 4: FLIP VERTICAL 5: TRANSPOSE 6: ROTATE 90 7: TRANSVERSE 8: * ROTATE 270/*from w w w .j a v a2 s .com*/ **********************************/ Bitmap rotateBitmap = bitMap; switch (rotation) { case ExifInterface.ORIENTATION_UNDEFINED: break; case ExifInterface.ORIENTATION_NORMAL: break; case ExifInterface.ORIENTATION_FLIP_HORIZONTAL: break; case ExifInterface.ORIENTATION_ROTATE_180: if (photoW > photoH) { Matrix matrix = new Matrix(); matrix.setRotate(180); rotateBitmap = Bitmap.createBitmap(bitMap, 0, 0, bitMap.getWidth(), bitMap.getHeight(), matrix, false); if (BaseActivity.DEBUG) MyLog.d(TAG, "Bitmap resized and rotated size: " + rotateBitmap.getWidth() + ", " + rotateBitmap.getHeight()); } break; case ExifInterface.ORIENTATION_FLIP_VERTICAL: break; case ExifInterface.ORIENTATION_TRANSPOSE: break; case ExifInterface.ORIENTATION_ROTATE_90: if (photoW > photoH) { Matrix matrix = new Matrix(); matrix.setRotate(90); rotateBitmap = Bitmap.createBitmap(bitMap, 0, 0, bitMap.getWidth(), bitMap.getHeight(), matrix, false); if (BaseActivity.DEBUG) MyLog.d(TAG, "Bitmap resized and rotated size: " + rotateBitmap.getWidth() + ", " + rotateBitmap.getHeight()); } break; case ExifInterface.ORIENTATION_TRANSVERSE: break; case ExifInterface.ORIENTATION_ROTATE_270: if (photoW > photoH) { Matrix matrix = new Matrix(); matrix.setRotate(270); rotateBitmap = Bitmap.createBitmap(bitMap, 0, 0, bitMap.getWidth(), bitMap.getHeight(), matrix, false); if (BaseActivity.DEBUG) MyLog.d(TAG, "Bitmap resized and rotated size: " + rotateBitmap.getWidth() + ", " + rotateBitmap.getHeight()); } break; default: break; } return rotateBitmap; } }