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:Main.java

/**
 * Expand the bitmap to the specified scale.
 *
 * @param bitmap to expand.//from  w  w  w  . j a v a  2 s  .c o m
 * @param scale  the expand scale, must be > 1.0.
 * @return the expanded bitmap.
 */
public static Bitmap expand(Bitmap bitmap, float scale) {
    if (scale <= 1.0f) {
        return bitmap.copy(bitmap.getConfig(), false);
    }

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

    return Bitmap.createBitmap(bitmap, 0, 0, (int) (scale * bitmap.getWidth()),
            (int) (scale * bitmap.getHeight()), matrix, true);
}

From source file:Main.java

public static Bitmap bitmapZoomByScale(Bitmap srcBitmap, float scaleWidth, float scaleHeight) {
    int srcWidth = srcBitmap.getWidth();
    int srcHeight = srcBitmap.getHeight();
    Matrix matrix = new Matrix();

    matrix.postScale(scaleWidth, scaleHeight);
    Bitmap resizedBitmap = Bitmap.createBitmap(srcBitmap, 0, 0, srcWidth, srcHeight, matrix, true);
    if (resizedBitmap != null) {
        srcBitmap = null;/*w  w  w .j a va2s  .c o  m*/
        return resizedBitmap;
    } else {
        return srcBitmap;
    }
}

From source file:Main.java

/**
 * Shrink the bitmap to the specified scale.
 *
 * @param bitmap to shrink.//from   www .ja v  a  2  s  .  co m
 * @param scale  the shrink scale, must be < 1.0.
 * @return the shrunk bitmap.
 */
public static Bitmap shrink(Bitmap bitmap, float scale) {
    if (scale >= 1.0f) {
        return bitmap.copy(bitmap.getConfig(), false);
    }

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

    return Bitmap.createBitmap(bitmap, 0, 0, (int) (scale * bitmap.getWidth()),
            (int) (scale * bitmap.getHeight()), matrix, true);
}

From source file:Main.java

public static Bitmap zoom(Bitmap bitmap, float sf) {
    Matrix matrix = new Matrix();
    matrix.postScale(sf, sf);
    return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
}

From source file:Main.java

public static Bitmap zoom(Bitmap bitmap, float wf, float hf) {
    Matrix matrix = new Matrix();
    matrix.postScale(wf, hf);
    return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
}

From source file:Main.java

public static Bitmap compressFixBitmap(Bitmap bitMap, int outWidth, int outHeight) {
    int width = bitMap.getWidth();
    int height = bitMap.getHeight();
    float scaleWidth = ((float) outWidth) / width;
    float scaleHeight = ((float) outHeight) / height;
    Matrix matrix = new Matrix();
    matrix.postScale(scaleWidth, scaleHeight);
    return Bitmap.createBitmap(bitMap, 0, 0, width, height, matrix, true);
}

From source file:Main.java

public static Bitmap resizeBitmap(Bitmap bm, int w, int h) {
    Bitmap BitmapOrg = bm;/*from  w  ww .  j av  a 2  s .  com*/

    int width = BitmapOrg.getWidth();
    int height = BitmapOrg.getHeight();

    float scaleWidth = ((float) w) / width;
    float scaleHeight = ((float) h) / height;

    Matrix matrix = new Matrix();
    matrix.postScale(scaleWidth, scaleHeight);
    return Bitmap.createBitmap(BitmapOrg, 0, 0, width, height, matrix, true);
}

From source file:Main.java

public static Bitmap resize(Bitmap bitmap, int targetWidth, int targetHeight) {
    if (bitmap == null || targetWidth < 0 || targetHeight < 0) {
        return null;
    }/*from   w w w .ja v a 2s.  co  m*/
    int pictureWidth = bitmap.getWidth();
    int pictureHeight = bitmap.getHeight();
    float scale = Math.min((float) targetWidth / pictureWidth, (float) targetHeight / pictureHeight); // (1)

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

    return Bitmap.createBitmap(bitmap, 0, 0, pictureWidth, pictureHeight, matrix, true);
}

From source file:Main.java

public static Drawable scaleImage(Drawable paramDrawable, float paramFloat1, float paramFloat2) {
    BitmapDrawable localBitmapDrawable = null;
    if (paramDrawable != null) {
        Bitmap localBitmap = ((BitmapDrawable) paramDrawable).getBitmap();
        int i = localBitmap.getWidth();
        int j = localBitmap.getHeight();
        Matrix localMatrix = new Matrix();
        localMatrix.postScale(paramFloat1, paramFloat2);
        localBitmapDrawable = new BitmapDrawable(
                Bitmap.createBitmap(localBitmap, 0, 0, i, j, localMatrix, true));
    }/*from   w  ww.j av  a  2 s . co  m*/
    return localBitmapDrawable;
}

From source file:Main.java

public static Bitmap scaleImg(Bitmap bm, int newWidth, int newHeight) {

    int width = bm.getWidth();
    int height = bm.getHeight();

    int newWidth1 = newWidth;
    int newHeight1 = newHeight;

    float scaleWidth = ((float) newWidth1) / width;
    float scaleHeight = ((float) newHeight1) / height;

    Matrix matrix = new Matrix();
    matrix.postScale(scaleWidth, scaleHeight);

    Bitmap newbm = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, true);
    return newbm;

}