Example usage for android.graphics Matrix setRotate

List of usage examples for android.graphics Matrix setRotate

Introduction

In this page you can find the example usage for android.graphics Matrix setRotate.

Prototype

public void setRotate(float degrees) 

Source Link

Document

Set the matrix to rotate about (0,0) by the specified number of degrees.

Usage

From source file:Main.java

public static Bitmap rotateBitmap(Bitmap source, int angle) {
    Matrix matrix = new Matrix();
    if (angle > 0)
        matrix.setRotate(angle);
    Bitmap bitmap = Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true);
    if (bitmap != source && !source.isRecycled())
        source.recycle();//ww w  .j  a  v a2s  .co m
    return bitmap;
}

From source file:Main.java

public static Matrix getRotateMatrix(String s) {
    Matrix matrix = new Matrix();
    String s1 = getPicOrientation(s);
    if (s1.equals("3"))
        matrix.setRotate(180F);
    else if (s1.equals("6"))
        matrix.setRotate(90F);//from   w  ww  .ja  v a 2s.  com
    else if (s1.equals("8"))
        matrix.setRotate(270F);
    else
        matrix.setRotate(0.0F);
    return matrix;
}

From source file:Main.java

public static Bitmap getTotateBitmap(Bitmap bitmap, int orientation) {
    Matrix matrix = new Matrix();

    switch (orientation) {
    case ExifInterface.ORIENTATION_ROTATE_90: {
        matrix.setRotate(90);
        bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
    }//from www . j  av  a  2  s. c  o m
        break;
    case ExifInterface.ORIENTATION_ROTATE_180: {
        matrix.setRotate(180);
        bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
    }
        break;
    case ExifInterface.ORIENTATION_ROTATE_270: {
        matrix.setRotate(270);
        bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
    }
        break;
    default:
        break;
    }
    return bitmap;
}

From source file:com.exzogeni.dk.graphics.Bitmaps.java

@NonNull
private static Matrix getExifMatrix(int orientation) {
    final Matrix matrix = new Matrix();
    if (orientation == ExifInterface.ORIENTATION_ROTATE_180) {
        matrix.setRotate(180);
    } else if (orientation == ExifInterface.ORIENTATION_ROTATE_90) {
        matrix.setRotate(90);//w  w w.  ja v a  2 s  .c  o m
    } else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) {
        matrix.setRotate(-90);
    }
    return matrix;
}

From source file:Main.java

public static Bitmap rotateBitmap(String src, Bitmap bitmap) {
    try {/*from   www  .  j  a va  2s.c o m*/
        int orientation = getExifOrientation(src);

        if (orientation == 1) {
            return bitmap;
        }

        Matrix matrix = new Matrix();
        switch (orientation) {
        case 2:
            matrix.setScale(-1, 1);
            break;
        case 3:
            matrix.setRotate(180);
            break;
        case 4:
            matrix.setRotate(180);
            matrix.postScale(-1, 1);
            break;
        case 5:
            matrix.setRotate(90);
            matrix.postScale(-1, 1);
            break;
        case 6:
            matrix.setRotate(90);
            break;
        case 7:
            matrix.setRotate(-90);
            matrix.postScale(-1, 1);
            break;
        case 8:
            matrix.setRotate(-90);
            break;
        default:
            return bitmap;
        }

        try {
            Bitmap oriented = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix,
                    true);
            bitmap.recycle();
            return oriented;
        } catch (OutOfMemoryError e) {
            e.printStackTrace();
            return bitmap;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

    return bitmap;
}

From source file:Main.java

public static Bitmap normalizeExifRotateBitmap(Bitmap bitmap, int orientation) {

    Matrix matrix = new Matrix();
    switch (orientation) {
    case ExifInterface.ORIENTATION_NORMAL:
        return bitmap;
    case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
        matrix.setScale(-1, 1);/*from   www.  ja va  2 s . c  o m*/
        break;
    case ExifInterface.ORIENTATION_ROTATE_180:
        matrix.setRotate(180);
        break;
    case ExifInterface.ORIENTATION_FLIP_VERTICAL:
        matrix.setRotate(180);
        matrix.postScale(-1, 1);
        break;
    case ExifInterface.ORIENTATION_TRANSPOSE:
        matrix.setRotate(90);
        matrix.postScale(-1, 1);
        break;
    case ExifInterface.ORIENTATION_ROTATE_90:
        matrix.setRotate(90);
        break;
    case ExifInterface.ORIENTATION_TRANSVERSE:
        matrix.setRotate(-90);
        matrix.postScale(-1, 1);
        break;
    case ExifInterface.ORIENTATION_ROTATE_270:
        matrix.setRotate(-90);
        break;
    default:
        return bitmap;
    }
    try {
        Bitmap bmRotated = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix,
                true);
        bitmap.recycle();
        return bmRotated;
    } catch (OutOfMemoryError e) {
        e.printStackTrace();
        return null;
    }
}

From source file:Main.java

public static Bitmap rotateBitmap(Bitmap bitmap, int exifOrientation) {
    Matrix matrix = new Matrix();
    switch (exifOrientation) {
    case ExifInterface.ORIENTATION_NORMAL:
    default:/*from   w  ww .j  a  va  2s .  c o m*/
        return bitmap;
    case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
        matrix.setScale(-1, 1);
        break;
    case ExifInterface.ORIENTATION_ROTATE_180:
        matrix.setRotate(180);
        break;
    case ExifInterface.ORIENTATION_FLIP_VERTICAL:
        matrix.setRotate(180);
        matrix.postScale(-1, 1);
        break;
    case ExifInterface.ORIENTATION_TRANSPOSE:
        matrix.setRotate(90);
        matrix.postScale(-1, 1);
        break;
    case ExifInterface.ORIENTATION_ROTATE_90:
        matrix.setRotate(90);
        break;
    case ExifInterface.ORIENTATION_TRANSVERSE:
        matrix.setRotate(-90);
        matrix.postScale(-1, 1);
        break;
    case ExifInterface.ORIENTATION_ROTATE_270:
        matrix.setRotate(-90);
        break;
    }

    try {
        return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);

    } catch (OutOfMemoryError e) {
        e.printStackTrace();
        return null;
    }
}

From source file:com.daiv.android.twitter.services.SendTweet.java

public static Bitmap rotateBitmap(Bitmap bitmap, int orientation) {

    Log.v("Test_composing_image", "rotation: " + orientation);

    try {// ww w. jav a2  s . co  m
        Matrix matrix = new Matrix();
        switch (orientation) {
        case ExifInterface.ORIENTATION_NORMAL:
            return bitmap;
        case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
            matrix.setScale(-1, 1);
            break;
        case ExifInterface.ORIENTATION_ROTATE_180:
            matrix.setRotate(180);
            break;
        case ExifInterface.ORIENTATION_FLIP_VERTICAL:
            matrix.setRotate(180);
            matrix.postScale(-1, 1);
            break;
        case ExifInterface.ORIENTATION_TRANSPOSE:
            matrix.setRotate(90);
            matrix.postScale(-1, 1);
            break;
        case ExifInterface.ORIENTATION_ROTATE_90:
            matrix.setRotate(90);
            break;
        case ExifInterface.ORIENTATION_TRANSVERSE:
            matrix.setRotate(-90);
            matrix.postScale(-1, 1);
            break;
        case ExifInterface.ORIENTATION_ROTATE_270:
            matrix.setRotate(-90);
            break;
        default:
            return bitmap;
        }
        try {
            Bitmap bmRotated = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix,
                    true);
            bitmap.recycle();
            return bmRotated;
        } catch (OutOfMemoryError e) {
            e.printStackTrace();
            return null;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return bitmap;
}

From source file:com.benefit.buy.library.http.query.callback.BitmapAjaxCallback.java

private static Matrix getRotateMatrix(int ori) {
    Matrix matrix = new Matrix();
    switch (ori) {
    case 2:/*  w  ww.  ja  v  a  2  s  . co  m*/
        matrix.setScale(-1, 1);
        break;
    case 3:
        matrix.setRotate(180);
        break;
    case 4:
        matrix.setRotate(180);
        matrix.postScale(-1, 1);
        break;
    case 5:
        matrix.setRotate(90);
        matrix.postScale(-1, 1);
        break;
    case 6:
        matrix.setRotate(90);
        break;
    case 7:
        matrix.setRotate(-90);
        matrix.postScale(-1, 1);
        break;
    case 8:
        matrix.setRotate(-90);
        break;
    }
    return matrix;
}

From source file:info.shibafu528.gallerymultipicker.ThumbnailAsyncTask.java

@Override
protected Bitmap doInBackground(ThumbParam... params) {
    Bitmap bitmap = cache.get(params[0].id);
    if (bitmap == null) {
        bitmap = MediaStore.Images.Thumbnails.getThumbnail(params[0].resolver, params[0].id,
                MediaStore.Images.Thumbnails.MINI_KIND, options);
        if (bitmap != null) {
            Matrix matrix = new Matrix();
            matrix.setRotate(params[0].orientation);
            bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
            cache.put(params[0].id, bitmap);
        }//  w  w  w .  j a v a 2 s . c o m
    }
    return bitmap;
}