Example usage for android.graphics Matrix postScale

List of usage examples for android.graphics Matrix postScale

Introduction

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

Prototype

public boolean postScale(float sx, float sy) 

Source Link

Document

Postconcats the matrix with the specified scale.

Usage

From source file:com.BeeFramework.Utils.Utils.java

public static Bitmap scaleBitmap(Bitmap bm, int dstHeight, int dstWidth) {
    if (bm == null)
        return null;//java.lang.NullPointerException
    int srcHeight = bm.getHeight();
    int srcWidth = bm.getWidth();
    if (srcHeight > dstHeight || srcWidth > dstWidth) {
        float scale_y = ((float) dstHeight) / srcHeight;
        float scale_x = ((float) dstWidth) / srcWidth;
        float scale = scale_y < scale_x ? scale_y : scale_x;
        Matrix matrix = new Matrix();
        matrix.postScale(scale, scale);
        Bitmap dstbmp = Bitmap.createBitmap(bm, 0, 0, srcWidth, srcHeight, matrix, true);
        return dstbmp;
    } else {/*from   w  ww.  j  a va  2  s  . c  o  m*/
        return Bitmap.createBitmap(bm);
    }
}

From source file:Main.java

public static Bitmap formatBitmap(Bitmap bitmap, int size) {

    float width = bitmap.getWidth();
    float height = bitmap.getHeight();
    float rota = size / height;

    int widthnew = (int) ((size * width) / height);
    // int wh = Math.max(bitmap.getWidth(), bitmap.getHeight());
    Bitmap mBitmap = Bitmap.createBitmap(widthnew, size, Bitmap.Config.ARGB_8888);
    Matrix matrix = new Matrix();
    matrix.postScale(rota, rota);
    Canvas canvas = new Canvas(mBitmap);
    canvas.drawBitmap(bitmap, matrix, null);

    // bitmap = Bitmap.createScaledBitmap(mBitmap, width, height, true);
    return mBitmap;
}

From source file:Main.java

/**
 * Shrinks and rotates (if necessary) a passed Bitmap.
 *
 * @param bm/*from  ww w  . j a  v a 2s .  c om*/
 * @param maxLengthOfEdge
 * @param rotateXDegree
 * @return Bitmap
 */
public static Bitmap shrinkBitmap(Bitmap bm, int maxLengthOfEdge, int rotateXDegree) {
    if (maxLengthOfEdge > bm.getWidth() && maxLengthOfEdge > bm.getHeight()) {
        return bm;
    } else {
        // shrink image
        float scale = (float) 1.0;
        if (bm.getHeight() > bm.getWidth()) {
            scale = ((float) maxLengthOfEdge) / bm.getHeight();
        } else {
            scale = ((float) maxLengthOfEdge) / bm.getWidth();
        }
        // CREATE CommonAsync MATRIX FOR THE MANIPULATION
        Matrix matrix = new Matrix();
        // RESIZE THE BIT MAP
        matrix.postScale(scale, scale);
        matrix.postRotate(rotateXDegree);

        // RECREATE THE NEW BITMAP
        bm = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), matrix, false);

        matrix = null;
        System.gc();

        return bm;
    }
}

From source file:com.BeeFramework.Utils.Utils.java

public static Bitmap scaleBitmap(Bitmap bm, int pixel) {
    int srcHeight = bm.getHeight();
    int srcWidth = bm.getWidth();

    if (srcHeight > pixel || srcWidth > pixel) {
        float scale_y = 0;
        float scale_x = 0;
        if (srcHeight > srcWidth) {
            scale_y = ((float) pixel) / srcHeight;
            scale_x = scale_y;//from   w  ww .  j  av  a2 s  .c o  m
        } else {
            scale_x = ((float) pixel) / srcWidth;
            scale_y = scale_x;
        }

        Matrix matrix = new Matrix();
        matrix.postScale(scale_x, scale_y);
        Bitmap dstbmp = Bitmap.createBitmap(bm, 0, 0, srcWidth, srcHeight, matrix, true);
        return dstbmp;
    } else {
        return Bitmap.createBitmap(bm);
    }
}

From source file:Main.java

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

From source file:Main.java

@SuppressWarnings("deprecation")
public static int PutImageScale(Canvas canvas, Drawable image, double Angle, int x, int y, double scale) {

    if (scale == 0.0)
        return 0;

    float newWidth = (int) Math.round((float) image.getIntrinsicWidth() * scale);
    float newHeight = (int) Math.round((float) image.getIntrinsicHeight() * scale);

    Bitmap bmp = ((BitmapDrawable) image).getBitmap();
    int width = bmp.getWidth();
    int height = bmp.getHeight();

    float scaleWidth = ((float) newWidth) / width;
    float scaleHeight = ((float) newHeight) / height;
    // createa matrix for the manipulation
    Matrix matrix = new Matrix();
    // resize the bit map
    matrix.postScale(scaleWidth, scaleHeight);
    // rotate the Bitmap
    matrix.postRotate((float) Angle);
    // recreate the new Bitmap
    Bitmap resizedBitmap = Bitmap.createBitmap(bmp, 0, 0, width, height, matrix, true);
    // make a Drawable from Bitmap to allow to set the BitMap
    // to the ImageView, ImageButton or what ever
    BitmapDrawable bmd = new BitmapDrawable(resizedBitmap);

    bmd.setBounds(x, y, x + bmd.getIntrinsicWidth(), y + bmd.getIntrinsicHeight());
    bmd.draw(canvas);/*from  w  w w . j av  a2s  .  co  m*/

    return bmd.getIntrinsicWidth();

}

From source file:Main.java

public static Bitmap zoomBitmap(Bitmap bitmap, int width, int height) {
    int w = bitmap.getWidth();
    int h = bitmap.getHeight();
    Bitmap newbmp;/*from w  w  w  .ja va2s. c  o  m*/
    try {
        // if (h >= w) {
        // if (height <= h) {
        Matrix matrix = new Matrix();
        float scaleHeight = ((float) height / h);
        matrix.postScale(scaleHeight, scaleHeight);
        newbmp = Bitmap.createBitmap(bitmap, 0, 0, w, h, matrix, true);
        return newbmp;
        // }
        // } else {
        // if (width <= w) {
        // Matrix matrix = new Matrix();
        // float scaleWidth = ((float) width / w);
        // matrix.postScale(scaleWidth, scaleWidth);
        // newbmp = Bitmap.createBitmap(bitmap, 0, 0, w, h, matrix,
        // true);
        // return newbmp;
        // }
        // }
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:Main.java

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

From source file:Main.java

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

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