Example usage for android.graphics Bitmap getHeight

List of usage examples for android.graphics Bitmap getHeight

Introduction

In this page you can find the example usage for android.graphics Bitmap getHeight.

Prototype

public final int getHeight() 

Source Link

Document

Returns the bitmap's height

Usage

From source file:Main.java

public static Bitmap compoundBitmap(Bitmap bg, Bitmap fg, int left, int top) {
    Bitmap result = Bitmap.createBitmap(bg.getWidth(), bg.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(result);
    canvas.drawBitmap(bg, 0, 0, null);//from  w  ww  .  j a  va2  s .c  o m
    canvas.drawBitmap(fg, left, top, null);

    return result;
}

From source file:Main.java

public static Bitmap bigImage(Bitmap bmp, float big) {
    int bmpWidth = bmp.getWidth();
    int bmpHeight = bmp.getHeight();
    Matrix matrix = new Matrix();
    matrix.postScale(big, big);/* w  w w .ja va  2 s  .  co  m*/
    return Bitmap.createBitmap(bmp, 0, 0, bmpWidth, bmpHeight, matrix, true);
}

From source file:Main.java

public static Bitmap resizeBitmap(Bitmap image, int maxSize) {
    int width = image.getWidth();
    int height = image.getHeight();
    float aspectRatio = width / (float) height;

    if (aspectRatio > 1) {
        width = maxSize;//from  w ww.j a va  2  s.  co  m
        height = Math.round(width / aspectRatio);
    } else {
        height = maxSize;
        width = Math.round(height * aspectRatio);
    }

    return Bitmap.createScaledBitmap(image, width, height, true);
}

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 cutMatrixBitmap(Bitmap src, float scale) {

    int srcW = src.getWidth();
    int srcH = src.getHeight();
    int matrixW = srcW;
    int matrixH = srcH;

    matrixW = (int) (matrixH * scale);
    if (matrixW > srcW) {
        matrixW = srcW;//from ww  w .  j a v  a2s .  c  om
        matrixH = (int) (srcW / scale);
    }
    int left = (srcW - matrixW) / 2;
    int top = (srcH - matrixH) / 2;

    return src == null ? Bitmap.createBitmap(matrixW, matrixH, Config.ARGB_8888)
            : Bitmap.createBitmap(src, left, top, matrixW, matrixH);
}

From source file:Main.java

public static Bitmap zoomBitmap(Bitmap bitmap, float times) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    Matrix matrix = new Matrix();
    matrix.postScale(times, times);//  w  w  w. ja  va  2s  . co m
    Bitmap zoomBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
    return zoomBitmap;
}

From source file:Main.java

public static Bitmap resize(Bitmap src, int w2, int h2) {
    int w1 = src.getWidth();
    int h1 = src.getHeight();
    int[] pxSource = new int[w1 * h1];
    int[] pxResult = new int[w2 * h2];

    src.getPixels(pxSource, 0, w1, 0, 0, w1, h1);
    double x_ratio = w1 / (double) w2;
    double y_ratio = h1 / (double) h2;
    double px, py;
    for (int i = 0; i < h2; i++) {
        for (int j = 0; j < w2; j++) {
            px = Math.floor(j * x_ratio);
            py = Math.floor(i * y_ratio);
            pxResult[(i * w2) + j] = pxSource[(int) ((py * w1) + px)];
        }/*w w w.j  a va 2  s .  c  om*/
    }

    return Bitmap.createBitmap(pxResult, w2, h2, Config.ARGB_8888);
}

From source file:Main.java

/**
 * Method to create a fully-transparent Bitmap using the same size of the source passed as
 * parameter and also the same density.//from  w  w  w .ja  va2 s . c  om
 *
 * @param source The original Bitmap.
 * @return A transparent Bitmap with the same size of the source.
 */
public static Bitmap clear(Bitmap source) {
    Bitmap newBitmap = Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight());
    //to erase the color from a Bitmap, I must use a mutable Bitmap!!!!
    Bitmap mutableBitmap = newBitmap.copy(Bitmap.Config.ARGB_8888, true);
    mutableBitmap.eraseColor(Color.TRANSPARENT);
    return mutableBitmap;
}

From source file:Main.java

public static Bitmap resizeBitmap(Bitmap bm, int w, int h) {
    Bitmap BitmapOrg = bm;

    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 handleColorMatrix(Bitmap bm, float[] matrixs) {
    Bitmap bitmap = Bitmap.createBitmap(bm.getWidth(), bm.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint();

    ColorMatrix colorMatrix = new ColorMatrix();
    colorMatrix.set(matrixs);/*from w  w  w .j av a  2 s  .c  o  m*/
    paint.setColorFilter(new ColorMatrixColorFilter(colorMatrix));

    canvas.drawBitmap(bm, 0, 0, paint);

    return bitmap;
}