Example usage for android.graphics Matrix Matrix

List of usage examples for android.graphics Matrix Matrix

Introduction

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

Prototype

public Matrix() 

Source Link

Document

Create an identity matrix

Usage

From source file:Main.java

/**
 * Gets invert matrix.//w  w w  .j  a v a 2 s  . c om
 *
 * @param matrix original matrix
 * @return invert matrix
 */
public static Matrix getInvertMatrix(Matrix matrix) {
    Matrix invertMatrix = new Matrix();
    matrix.invert(invertMatrix);
    return invertMatrix;
}

From source file:Main.java

public static Bitmap zoomBMP(Bitmap bitmap, int w, int h) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    Matrix matrix = new Matrix();
    float scaleWidth = (float) w / (float) width;
    float scaleHeight = (float) h / (float) height;
    matrix.postScale(scaleWidth, scaleHeight);
    Bitmap newBmp = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
    return newBmp;
}

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  va2  s  .co 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 sourceBitmap, float angleInDegrees) {
    if (angleInDegrees == 0)
        return sourceBitmap;
    Matrix matrix = new Matrix();
    matrix.postRotate(angleInDegrees);//from   w  ww.j  a va  2s.  c  o  m
    return Bitmap.createBitmap(sourceBitmap, 0, 0, sourceBitmap.getWidth(), sourceBitmap.getHeight(), matrix,
            true);
}

From source file:Main.java

public static Bitmap rotateBitmap(Bitmap bitmap, int rotate) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();

    Matrix matrix = new Matrix();
    matrix.postRotate(rotate);/*from  w  w w.ja v  a 2 s.  com*/

    return Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, false);
}

From source file:Main.java

public static Bitmap zoomBitmap(Bitmap bitmap, int w, int h) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    Matrix matrix = new Matrix();
    float scaleWidht = ((float) w / width);
    float scaleHeight = ((float) h / height);
    matrix.postScale(scaleWidht, scaleHeight);
    Bitmap newbmp = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
    return newbmp;
}

From source file:Main.java

public static Bitmap rotation90(Bitmap bitmap) {
    if (bitmap == null)
        return null;
    if (bitmap.isRecycled())
        return null;
    Bitmap bmp = null;//from  w ww  .  j  a v  a 2s .com
    Matrix matrix = new Matrix();
    matrix.postRotate(90);
    bmp = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, false);
    bitmap.recycle();
    return bmp;
}

From source file:Main.java

public static Bitmap zoomBitmap(Bitmap bitmap, int w, int h) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    Matrix matrix = new Matrix();
    float scaleWidth = (float) w / (float) width;
    float scaleHeight = (float) h / (float) height;
    matrix.postScale(scaleWidth, scaleHeight);
    Bitmap newBmp = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
    return newBmp;
}

From source file:Main.java

public static Bitmap rotateBitmap(int degrees, Bitmap bitmap) {
    if (degrees == 0 || null == bitmap) {
        return bitmap;
    }/* w w w  .  j  ava2  s .  c om*/
    Matrix matrix = new Matrix();
    matrix.setRotate(degrees, bitmap.getWidth() / 2, bitmap.getHeight() / 2);
    Bitmap bmp = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
    if (null != bitmap) {
        bitmap.recycle();
        bitmap = null;
    }
    return bmp;
}

From source file:Main.java

/**
 * Rotate the bitmap with the specif angle
 *
 * @param angle/*from   w  w w .  j a va2  s.  c  o m*/
 * @param bitmap
 * @return Bitmap
 */
public static Bitmap rotateImageView(int angle, Bitmap bitmap) {
    Matrix matrix = new Matrix();
    matrix.postRotate(angle);
    System.out.println("angle2=" + angle);
    return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
}