Android Bitmap Resize manageBitmapRotatio(int photoW, int photoH, Bitmap bitMap, int rotation)

Here you can find the source of manageBitmapRotatio(int photoW, int photoH, Bitmap bitMap, int rotation)

Description

manage Bitmap Rotatio

Declaration

public static Bitmap manageBitmapRotatio(int photoW, int photoH,
            Bitmap bitMap, int rotation) 

Method Source Code

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;
    }
}

Related

  1. calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight)
  2. calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight)
  3. createFitCenterBitmap(Bitmap srcBitmap, int dstWidth, int dstHeight, boolean tryRecycleSource)
  4. createFitXYBitmap(Bitmap srcBitmap, int dstWidth, int dstHeight, boolean tryRecycleSource)
  5. getSampledBitmap(String filePath, int reqWidth, int reqHeight)
  6. readBitmapAutoSize(String filePath, int outWidth, int outHeight)
  7. resize(Bitmap bitmap, int newWidth, int newHeight)
  8. resizeAndCropCenter(Bitmap bitmap, int size, boolean recycle)
  9. resizeAndCropCenter(final Bitmap bitmap, final int size)