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

/**
 * Fill the hole in the image (version 2)
 *//* w  ww.  j av  a2  s. c om*/
public static void fillHole2(Bitmap bmp) {

    for (int j = 1; j < bmp.getWidth(); j++) {
        for (int i = 1; i < bmp.getHeight() - 1; i++) {
            if ((bmp.getPixel(i, j) == Color.TRANSPARENT) && (bmp.getPixel(i + 1, j) != Color.TRANSPARENT)) {
                bmp.setPixel(i, j, bmp.getPixel(i + 1, j)); // set to the next-below pixel
            }
        }
    }
}

From source file:Main.java

/**
 * Fill the hole in the image (version 1)
 *//*  w w  w . j  ava2  s. c o  m*/
public static void fillHole1(Bitmap bmp) {

    for (int j = 1; j < bmp.getWidth() - 1; j++) {
        for (int i = 1; i < bmp.getHeight(); i++) {
            if ((bmp.getPixel(i, j) == Color.TRANSPARENT) && (bmp.getPixel(i, j + 1) != Color.TRANSPARENT)) {
                bmp.setPixel(i, j, bmp.getPixel(i, j + 1)); // set to the right-next pixel
            }
        }
    }
}

From source file:Main.java

public static Bitmap getResizedBitmap(Bitmap bitmap, int i, int j) {
    int k = bitmap.getWidth();
    int l = bitmap.getHeight();
    float f = (float) i / (float) k;
    float f1 = (float) j / (float) l;
    Matrix matrix = new Matrix();
    matrix.postScale(f, f1);//from w  w w  . j  a v  a 2  s .c  om
    return Bitmap.createBitmap(bitmap, 0, 0, k, l, matrix, false);
}

From source file:Main.java

public static Bitmap zoomBitmap(Bitmap bitmap, float scale) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    Matrix matrix = new Matrix();
    matrix.postScale(scale, scale);/*from w w w .  j  a va  2s.  c  o m*/
    Bitmap newbmp = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
    return newbmp;
}

From source file:Main.java

public static Bitmap rotateBitmap(Bitmap bitmap, int rotate) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();

    Matrix matrix = new Matrix();
    matrix.postRotate(rotate);//  w ww. ja  va 2  s.  c om

    return Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, false);
}

From source file:Main.java

public static Bitmap decodeBitmap(Bitmap bitmap, int orientation) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    Matrix mtx = new Matrix();
    mtx.postRotate(orientation);/*from w  w w.  j  av a2 s .c o m*/
    return Bitmap.createBitmap(bitmap, 0, 0, width, height, mtx, true);
}

From source file:Main.java

public static Bitmap getSaturationBitmap(Bitmap bitmap) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    Bitmap faceIconGreyBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(faceIconGreyBitmap);
    Paint paint = new Paint();
    ColorMatrix colorMatrix = new ColorMatrix();
    colorMatrix.setSaturation(0);// ww w .  ja va 2s. c o  m
    ColorMatrixColorFilter colorMatrixFilter = new ColorMatrixColorFilter(colorMatrix);
    paint.setColorFilter(colorMatrixFilter);
    canvas.drawBitmap(bitmap, 0, 0, paint);
    return faceIconGreyBitmap;
}

From source file:Main.java

/**
 * @param bitmap//from w  w w .ja v a 2s .  co m
 * @param matrix
 * @return
 * Function to get a square image once cropped from a rectangular image..
 */
public static Bitmap getSquareImage(Bitmap bitmap, Matrix matrix) {
    if (bitmap.getWidth() >= bitmap.getHeight()) {
        return Bitmap.createBitmap(bitmap, bitmap.getWidth() / 2 - bitmap.getHeight() / 2, 0,
                bitmap.getHeight(), bitmap.getHeight(), matrix, false);
    } else {
        return Bitmap.createBitmap(bitmap, 0, bitmap.getHeight() / 2 - bitmap.getWidth() / 2, bitmap.getWidth(),
                bitmap.getWidth(), matrix, false);
    }
}

From source file:Main.java

public static Bitmap scaleToFitWidth(Bitmap b, int width) {
    float factor = width / (float) b.getWidth();
    return Bitmap.createScaledBitmap(b, width, (int) (b.getHeight() * factor), true);
}

From source file:Main.java

static public Bitmap scaleToFitWidth(Bitmap b, int width) {
    float factor = width / (float) b.getWidth();
    return Bitmap.createScaledBitmap(b, width, (int) (b.getHeight() * factor), false);
}