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

public static Bitmap zoomBitmap3(Bitmap bitmap, int w, int h) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    Matrix matrix = new Matrix();
    float ratio = ((float) w / width);

    matrix.postScale(ratio, ratio);//from w  w  w.j ava  2  s. c  o m
    Bitmap newbmp = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
    return newbmp;
}

From source file:Main.java

public synchronized static Bitmap getRotatedBitmap(Bitmap bitmap, int degrees) {
    if (degrees != 0 && bitmap != null) {
        Matrix m = new Matrix();
        m.setRotate(degrees, (float) bitmap.getWidth() / 2, (float) bitmap.getHeight() / 2);
        try {//  www.jav  a2  s .  c  om
            Bitmap b2 = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), m, true);
            if (bitmap != b2) {
                bitmap.recycle();
                bitmap = b2;
            }
        } catch (OutOfMemoryError e) {
            // Log.d(PhotoUtil.class.getSimpleName(),
            // "Error: "+e.getMessage());
        }
    }

    return bitmap;
}

From source file:Main.java

public static Bitmap getFixedBitmap(Bitmap bm, int w, int h, boolean filter) {
    int width = bm.getWidth();
    int height = bm.getHeight();
    Matrix matrix = new Matrix();
    matrix.postScale((float) w / width, (float) h / height);
    return Bitmap.createBitmap(bm, 0, 0, width, height, matrix, filter);
}

From source file:Main.java

public static Bitmap rotateBitmap(Bitmap bitmap, float degrees) {
    Bitmap resizeBmp = null;//  w w w .j a  v a2  s . c  o m
    if (bitmap != null && degrees > 0) {
        Matrix matrix = new Matrix();
        matrix.setRotate(degrees);
        resizeBmp = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
    }
    return resizeBmp;
}

From source file:Main.java

public static Bitmap GetMirror(Bitmap bm) {
    if (bm == null)
        return null;

    float[] mirrorM = { -1, 0, 0, 0, 1, 0, 0, 0, 1 };

    Matrix m = new Matrix();
    m.setValues(mirrorM);//w  w  w.  j a  v  a  2  s.c  o  m
    return Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), m, false);
}

From source file:Main.java

public static Bitmap postRotateBitamp(Bitmap bmp, float degree) {

    int bmpWidth = bmp.getWidth();
    int bmpHeight = bmp.getHeight();

    Matrix matrix = new Matrix();
    matrix.postRotate(degree);/*from w w  w .  j  ava 2  s  .co  m*/
    Bitmap resizeBmp = Bitmap.createBitmap(bmp, 0, 0, bmpWidth, bmpHeight, matrix, true);
    return resizeBmp;
}

From source file:Main.java

public final static Bitmap rotate(Bitmap b, float degrees) {
    if (degrees != 0 && b != null) {
        Matrix m = new Matrix();
        m.setRotate(degrees, (float) b.getWidth() / 2, (float) b.getHeight() / 2);

        Bitmap b2 = Bitmap.createBitmap(b, 0, 0, b.getWidth(), b.getHeight(), m, true);
        if (b != b2) {
            b.recycle();// w  ww .  ja v a  2  s. co m
            b = b2;
        }

    }
    return b;
}

From source file:Main.java

public static Bitmap getRotatedBitmap(Bitmap mBitmap, float degrees) {
    int width = mBitmap.getWidth();
    int height = mBitmap.getHeight();

    Matrix matrix = new Matrix();
    matrix.postRotate(degrees);/*from   ww  w. j a v  a  2 s. co m*/
    Bitmap mRotateBitmap = Bitmap.createBitmap(mBitmap, 0, 0, width, height, matrix, true);

    return mRotateBitmap;
}

From source file:Main.java

public static Bitmap getRotateBitmap(Bitmap bitmap, int rotation) {
    if (null == bitmap || bitmap.isRecycled()) {
        return null;
    }/*from   w  w  w . ja va2 s .  c o m*/

    Matrix matrix = new Matrix();
    matrix.postRotate(rotation);
    Bitmap cropBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, false);
    return cropBitmap;
}

From source file:Main.java

private static Bitmap createScaledBitmap(Bitmap bitmap, float scale, int width, int height) {
    if (bitmap == null) {
        return null;
    }/*  w w w.  j a  v a2s .co  m*/

    Matrix matrix = new Matrix();
    matrix.postScale(scale, scale);

    Bitmap scaledBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);

    return scaledBitmap;
}