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 zoomBitmapScale(Bitmap bitmap, float sx, float sy) {
    if (sx <= 0 || sy <= 0) {
        return bitmap;
    }/*from  ww w.  j  ava  2  s  . c om*/
    if (bitmap == null) {
        return null;
    }
    Matrix matrix = new Matrix();
    matrix.postScale(sx, sx);
    return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
}

From source file:Main.java

public static Bitmap overlayToDownCenter(Bitmap bmp1, Bitmap bmp2) {
    Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig());
    Canvas canvas = new Canvas(bmOverlay);
    canvas.drawBitmap(bmp1, new Matrix(), null);
    Matrix matrix = new Matrix();
    matrix.setTranslate(((float) bmp1.getWidth() - bmp2.getWidth()) / 2, bmp1.getHeight() - bmp2.getHeight());
    canvas.drawBitmap(bmp2, matrix, null);
    return bmOverlay;
}

From source file:Main.java

public static Bitmap overlayToDownRightCorner(Bitmap bmp1, Bitmap bmp2) {
    Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig());
    Canvas canvas = new Canvas(bmOverlay);
    canvas.drawBitmap(bmp1, new Matrix(), null);
    Matrix matrix = new Matrix();
    matrix.setTranslate(bmp1.getWidth() - bmp2.getWidth(), bmp1.getHeight() - bmp2.getHeight());
    canvas.drawBitmap(bmp2, matrix, null);
    return bmOverlay;
}

From source file:Main.java

/**
 * Get a mirror Bitmap/*  w w  w  . j av  a  2  s  .c o m*/
 *
 * @param sourceBitmap Bitmap to Change
 * @return Mirror bitmap
 */
public static Bitmap getMirrorBitmap(Bitmap sourceBitmap) {
    Matrix m = new Matrix();
    m.preScale(-1, 1);
    Bitmap dst = Bitmap.createBitmap(sourceBitmap, 0, 0, sourceBitmap.getWidth(), sourceBitmap.getHeight(), m,
            false);
    dst.setDensity(DisplayMetrics.DENSITY_DEFAULT);
    return dst;
}

From source file:Main.java

public static Bitmap rotate(Bitmap originalBitmap, float alpha) {
    if (originalBitmap == null)
        return null;
    int width = originalBitmap.getWidth();
    int height = originalBitmap.getHeight();
    Matrix matrix = new Matrix();
    matrix.setRotate(alpha);//ww  w  . j a  v  a 2  s .  c  o m
    return Bitmap.createBitmap(originalBitmap, 0, 0, width, height, matrix, true);
}

From source file:Main.java

public static Bitmap getResizedBitmap(Bitmap bitmap, int i, int j) {
    int k = bitmap.getWidth();
    int l = bitmap.getHeight();
    float f = (float) i / (float) k;
    float f1 = (float) j / (float) l;
    Matrix matrix = new Matrix();
    matrix.postScale(f, f1);/*w w  w  .  jav a2  s . c  om*/
    return Bitmap.createBitmap(bitmap, 0, 0, k, l, matrix, false);
}

From source file:Main.java

public static Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth) {
    int width = bm.getWidth();
    int height = bm.getHeight();
    float scaleWidth = ((float) newWidth) / width;
    float scaleHeight = ((float) newHeight) / height;
    Matrix matrix = new Matrix();
    matrix.postScale(scaleWidth, scaleHeight);
    Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);
    return resizedBitmap;
}

From source file:Main.java

public static Bitmap zoomBitmapSize(Bitmap bitmap, float width, float height) {
    if (width <= 0 || height <= 0) {
        return bitmap;
    }/*  www . j a  va2 s  . co m*/
    if (bitmap == null) {
        return null;
    }
    Matrix matrix = new Matrix();
    matrix.postScale(width / bitmap.getWidth(), height / bitmap.getHeight());
    return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
}

From source file:Main.java

public static Bitmap rotateBitmap(Bitmap bm, int direction) {
    Bitmap returnBm;// ww  w  .ja  va 2  s .  c  o m
    int w = bm.getWidth();
    int h = bm.getHeight();

    Matrix matrix = new Matrix();
    if (direction == ROTATE_LEFT) {
        matrix.postRotate(-90);
    } else if (direction == ROTATE_RIGHT) {
        matrix.postRotate(90);
    }

    returnBm = Bitmap.createBitmap(bm, 0, 0, w, h, matrix, true);

    if (bm != returnBm) {
        bm.recycle();
    }

    return returnBm;
}

From source file:Main.java

public static Bitmap resizeBitmap(Bitmap bitmap, int maxLength) {
    if (null == bitmap)
        return null;
    int w = bitmap.getWidth();
    int h = bitmap.getHeight();
    float scale = (float) maxLength / h;
    Matrix matrix = new Matrix();
    matrix.postScale(scale, scale);// ww  w. j  ava  2 s. com
    Bitmap zoomedBitmap = Bitmap.createBitmap(bitmap, 0, 0, w, h, matrix, true);
    return zoomedBitmap;
}