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

/**
 * scale image//w  w  w. j  av a  2 s .co m
 * @param src
 * @param scaleWidth
 * @param scaleHeight
 * @return
 */
public static Bitmap scaleImage(Bitmap src, float scaleWidth, float scaleHeight) {
    if (src == null) {
        return null;
    }
    Matrix matrix = new Matrix();
    matrix.postScale(scaleWidth, scaleHeight);
    return Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true);
}

From source file:Main.java

public static Bitmap drawImageBorder(Bitmap srcBitmap, Bitmap borderBitmap) {
    if (srcBitmap == null)
        throw new NullPointerException("srcBitmap should not null");
    if (borderBitmap == null)
        return srcBitmap;
    Bitmap temp = srcBitmap.copy(Config.ARGB_8888, true);
    /*Bitmap border = borderBitmap;
    if (srcBitmap.getWidth() != borderBitmap.getWidth() || 
      srcBitmap.getHeight() != borderBitmap.getHeight()) {
       border = zoomBitmap(borderBitmap, srcBitmap.getWidth(), srcBitmap.getHeight());
    }*///from   ww  w  .  ja v a2  s  . co m
    Canvas canvas = new Canvas(temp);
    Matrix m = new Matrix();
    m.postScale((float) temp.getWidth() / borderBitmap.getWidth(),
            (float) temp.getHeight() / borderBitmap.getHeight());
    //canvas.drawBitmap(border, 0, 0, null);
    canvas.drawBitmap(borderBitmap, m, null);
    return temp;
}

From source file:Main.java

public static Bitmap getScreenFitBitmap(Bitmap src, int dispWidth, int dispHeight) {
    int srcWidth = src.getWidth();
    int srcHeight = src.getHeight();

    float scale = (float) dispWidth / srcWidth;

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

    return Bitmap.createBitmap(src, 0, 0, srcWidth, srcHeight, matrix, true);
}

From source file:Main.java

public static Bitmap imageScale(Bitmap bitmap, int dst_w, int dst_h) {
    int src_w = bitmap.getWidth();
    int src_h = bitmap.getHeight();
    float scale_w = ((float) dst_w) / src_w;
    float scale_h = ((float) dst_h) / src_h;
    Matrix matrix = new Matrix();
    matrix.postScale(scale_w, scale_h);
    Bitmap dstbmp = Bitmap.createBitmap(bitmap, 0, 0, src_w, src_h, matrix, true);
    return dstbmp;
}

From source file:Main.java

public static Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth) {
    final int w = bm.getWidth();
    final int h = bm.getHeight();
    final float sw = ((float) newWidth) / w;
    final float sh = ((float) newHeight) / h;

    Matrix matrix = new Matrix();
    matrix.postScale(sw, sh);
    return Bitmap.createBitmap(bm, 0, 0, w, h, matrix, false);
}

From source file:Main.java

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

From source file:Main.java

public static Drawable scaleImage(Drawable drawable, float scaleWidth, float scaleHeight) {
    Drawable resizedDrawable = null;//from w  w  w. ja v  a2s. com
    if (drawable != null) {
        Bitmap bitmapOrg = ((BitmapDrawable) drawable).getBitmap();
        int width = bitmapOrg.getWidth();
        int height = bitmapOrg.getHeight();

        Matrix matrix = new Matrix();

        matrix.postScale(scaleWidth, scaleHeight);
        Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0, width, height, matrix, true);

        resizedDrawable = new BitmapDrawable(resizedBitmap);
    }
    return resizedDrawable;
}

From source file:Main.java

public static Bitmap compressBitmap(Bitmap bitmap, int width, int height, boolean isAdjust) {
    if (bitmap.getWidth() > width || bitmap.getHeight() > height) {
        float scaleX = new BigDecimal(width).divide(new BigDecimal(bitmap.getWidth()), 4, BigDecimal.ROUND_DOWN)
                .floatValue();//  w ww.  ja v a2s.  co  m
        float scaleY = new BigDecimal(height)
                .divide(new BigDecimal(bitmap.getHeight()), 4, BigDecimal.ROUND_DOWN).floatValue();
        if (isAdjust) {
            scaleX = (scaleX < scaleY ? scaleX : scaleY);
            scaleY = scaleX;
        }
        Matrix matrix = new Matrix();
        matrix.postScale(scaleX, scaleY);
        bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
    }
    return bitmap;
}

From source file:Main.java

public static Bitmap resize(final Bitmap b, final int newWidth, final int newHeight) {
    if (b == null) {
        return null;
    }//from  w  w  w. j  av  a  2 s  . c o  m

    int oldWidth = b.getWidth();
    int oldHeight = b.getHeight();
    if (oldWidth == newWidth && oldHeight == newHeight) {
        return b;
    }
    float scaleWidth = ((float) newWidth) / oldWidth;
    float scaleHeight = ((float) newHeight) / oldHeight;
    float scaleFactor = Math.min(scaleWidth, scaleHeight);
    Matrix scale = new Matrix();
    scale.postScale(scaleFactor, scaleFactor);

    Bitmap result = Bitmap.createBitmap(b, 0, 0, oldWidth, oldHeight, scale, false);
    b.recycle();
    return result;
}

From source file:Main.java

public static Bitmap createResizedBitmap(Bitmap srcBit, int newWidth, int newHeight) {
    int width = srcBit.getWidth();
    int height = srcBit.getHeight();

    // calculate the scale - in this case = 0.4f
    float scaleWidth = ((float) newWidth) / width;
    float scaleHeight = ((float) newHeight) / height;

    Matrix matrix = new Matrix();
    matrix.postScale(scaleWidth, scaleHeight);
    Bitmap resizedBitmap = Bitmap.createBitmap(srcBit, 0, 0, width, height, matrix, true);

    width = resizedBitmap.getWidth();// w  w  w  . java 2s .c om
    height = resizedBitmap.getHeight();

    Log.i("ImageResize",
            "Image Resize Result : " + Boolean.toString((newHeight == height) && (newWidth == width)));
    return resizedBitmap;
}