Example usage for android.graphics Bitmap getWidth

List of usage examples for android.graphics Bitmap getWidth

Introduction

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

Prototype

public final int getWidth() 

Source Link

Document

Returns the bitmap's width

Usage

From source file:Main.java

public static Bitmap scaleBitmap(Bitmap bitmap, float pct) {
    return Bitmap.createScaledBitmap(bitmap, Math.round(bitmap.getWidth() * pct),
            Math.round(bitmap.getHeight() * pct), true);
}

From source file:Main.java

public static Bitmap generateGrayImage(Bitmap bm) {
    Bitmap bitmap = Bitmap.createBitmap(bm.getWidth(), bm.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint();

    float[] matrixs = new float[] { 0.33f, 0.59f, 0.11f, 0, 0, 0.33f, 0.59f, 0.11f, 0, 0, 0.33f, 0.59f, 0.11f,
            0, 0, 0, 0, 0, 1, 0 };/*from w  ww  .  j av a2s  . com*/

    ColorMatrix colorMatrix = new ColorMatrix();
    colorMatrix.set(matrixs);
    paint.setColorFilter(new ColorMatrixColorFilter(colorMatrix));

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

    return bitmap;
}

From source file:Main.java

public static Bitmap highSaturationImage(Bitmap bm) {
    Bitmap bitmap = Bitmap.createBitmap(bm.getWidth(), bm.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint();

    float[] matrixs = new float[] { 1.438f, -0.122f, -0.016f, 0, -0.03f, -0.062f, 1.378f, -0.016f, 0, 0.05f,
            -0.062f, -0.122f, 1.438f, 0, -0.02f, 0, 0, 0, 1, 0 };

    ColorMatrix colorMatrix = new ColorMatrix();
    colorMatrix.set(matrixs);/*  ww w .j  a  v a 2s  .co m*/
    paint.setColorFilter(new ColorMatrixColorFilter(colorMatrix));

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

    return bitmap;
}

From source file:Main.java

/**
 * Heuristic method to determine if the image looks empty. Works by taking a horisontal row of pixels from he
 * middle, and looks if they're all pure white.
 *
 * @param refinedImage A pre-processed image of the evolution cost. (should be pre-refined to replace all non
 *                     text colors with pure white)
 * @return true if the image is likely only white
 *//* ww  w  .ja v a2  s  . co  m*/
private static boolean isOnlyWhite(Bitmap refinedImage) {
    int[] pixelArray = new int[refinedImage.getWidth()];

    //below code takes one line of pixels in the middle of the pixture from left to right
    refinedImage.getPixels(pixelArray, 0, refinedImage.getWidth(), 0, refinedImage.getHeight() / 2,
            refinedImage.getWidth(), 1);

    for (int pixel : pixelArray) {
        if (pixel != Color.rgb(255, 255, 255)) { // if pixel is not white
            return false;
        }
    }
    return true;
}

From source file:Main.java

public static Bitmap crop(Bitmap srcBmp, int side) {

    Bitmap dstBmp;//from w  w  w  .  j  a v  a 2 s  .  co m

    if (srcBmp.getWidth() >= srcBmp.getHeight()) {

        dstBmp = Bitmap.createBitmap(srcBmp, srcBmp.getWidth() / 2 - srcBmp.getHeight() / 2, 0,
                srcBmp.getHeight(), srcBmp.getHeight());

    } else {

        dstBmp = Bitmap.createBitmap(srcBmp, 0, srcBmp.getHeight() / 2 - srcBmp.getWidth() / 2,
                srcBmp.getWidth(), srcBmp.getWidth());
    }

    return Bitmap.createScaledBitmap(dstBmp, side, side, true);
}

From source file:Main.java

public static Bitmap getResizedBitmap(Bitmap bitmap, int newHeight, int newWidth) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    float scaleWidth = ((float) newWidth) / width;
    float scaleHeight = ((float) newHeight) / height;
    // CREATE A MATRIX FOR THE MANIPULATION
    Matrix matrix = new Matrix();
    // RESIZE THE BIT MAP
    matrix.postScale(scaleWidth, scaleHeight);
    // RECREATE THE NEW BITMAP
    Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, false);

    return resizedBitmap;
}

From source file:Main.java

public static Bitmap getSolideSizeBitmap(Bitmap bm, int width, int height) {
    float widthScale = (width * 1f) / (bm.getWidth() * 1f);
    float heightScale = (height * 1f) / (bm.getHeight() * 1f);
    Matrix matrix = new Matrix();
    matrix.setScale(widthScale, heightScale);
    return Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), matrix, false);
}

From source file:Main.java

public static Bitmap forceEvenBitmapSize(Bitmap original) {
    int width = original.getWidth();
    int height = original.getHeight();

    if (width % 2 == 1) {
        width++;//from  w  w  w  . j  av a  2s.c o m
    }
    if (height % 2 == 1) {
        height++;
    }

    Bitmap fixedBitmap = original;
    if (width != original.getWidth() || height != original.getHeight()) {
        fixedBitmap = Bitmap.createScaledBitmap(original, width, height, false);
    }

    if (fixedBitmap != original) {
        original.recycle();
    }

    return fixedBitmap;
}

From source file:Main.java

public static Bitmap roundCorner(Bitmap src, float round) {
    int width = src.getWidth();
    int height = src.getHeight();
    Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(result);
    canvas.drawARGB(0, 0, 0, 0);/*from w w  w  .j  av a  2  s. co m*/

    final Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setColor(Color.BLACK);

    final Rect rect = new Rect(0, 0, width, height);
    final RectF rectF = new RectF(rect);

    canvas.drawRoundRect(rectF, round, round, paint);

    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(src, rect, rect, paint);

    return result;
}

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);/*from  w w  w . ja v  a2s.c om*/
    Bitmap dstbmp = Bitmap.createBitmap(bitmap, 0, 0, src_w, src_h, matrix, true);
    return dstbmp;
}