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 cutBitmap(Bitmap bitmap, int nwidth, int nHeight) {
    if (null == bitmap || nwidth > bitmap.getWidth() || nHeight > bitmap.getHeight()) {
        return null;
    }/*  w  w w  .jav  a2 s  .  c  om*/
    Bitmap result = Bitmap.createBitmap(bitmap, 0, 0, nwidth, nHeight);
    return result;
}

From source file:Main.java

public static byte[][] bitmap2grayByteArry(Bitmap bm) {
    byte[][] grayImage = new byte[bm.getHeight()][bm.getWidth()];
    for (int i = 0; i < bm.getWidth(); i++) {
        for (int j = 0; j < bm.getHeight(); j++) {
            if (bm.getPixel(i, j) == Color.WHITE) {
                grayImage[j][i] = 0;// w w  w .  ja v  a 2  s  .  c  om
            } else {
                grayImage[j][i] = 1;
            }
        }
    }
    return grayImage;
}

From source file:Main.java

private static int[] reduceColor(Bitmap bitmap) {
    sum = 0;/*  w  ww.java  2s  .  c o m*/
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    int[] grayValues = new int[width * height];
    int[] pix = new int[width * height];
    bitmap.getPixels(pix, 0, width, 0, 0, width, height);
    for (int i = 0; i < width; i++)
        for (int j = 0; j < height; j++) {
            int x = j * width + i;
            int r = (pix[x] >> 16) & 0xff;
            int g = (pix[x] >> 8) & 0xff;
            int b = pix[x] & 0xff;
            int grayValue = (r * 30 + g * 59 + b * 11) / 100;
            sum += grayValue;
            grayValues[x] = grayValue;
        }
    return grayValues;
}

From source file:Main.java

public static Bitmap circleCrop(Bitmap bitmap) {
    int size = Math.min(bitmap.getWidth(), bitmap.getHeight());

    Bitmap output = Bitmap.createBitmap(size, size, Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, size, size);

    paint.setAntiAlias(true);/*from w  ww  .  ja v  a2  s.  com*/
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    // canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
    canvas.drawCircle(size / 2, size / 2, size / 2, paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    // Bitmap _bmp = Bitmap.createScaledBitmap(output, 60, 60, false);
    // return _bmp;
    return output;
}

From source file:Main.java

public static Bitmap overlayToDownCenter(Bitmap bmp1, Bitmap bmp2) {
    Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig());
    Canvas canvas = new Canvas(bmOverlay);
    canvas.drawBitmap(bmp1, new Matrix(), null);
    Matrix matrix = new Matrix();
    matrix.setTranslate(((float) bmp1.getWidth() - bmp2.getWidth()) / 2, bmp1.getHeight() - bmp2.getHeight());
    canvas.drawBitmap(bmp2, matrix, null);
    return bmOverlay;
}

From source file:Main.java

public static Bitmap overlayToDownRightCorner(Bitmap bmp1, Bitmap bmp2) {
    Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig());
    Canvas canvas = new Canvas(bmOverlay);
    canvas.drawBitmap(bmp1, new Matrix(), null);
    Matrix matrix = new Matrix();
    matrix.setTranslate(bmp1.getWidth() - bmp2.getWidth(), bmp1.getHeight() - bmp2.getHeight());
    canvas.drawBitmap(bmp2, matrix, null);
    return bmOverlay;
}

From source file:Main.java

public static Bitmap makeRoundedCornerBitmap(Bitmap bitmap, float roundPx) {
    int w = bitmap.getWidth();
    int h = bitmap.getHeight();
    Bitmap output = Bitmap.createBitmap(w, h, Config.ARGB_8888);
    Canvas canvas = new Canvas(output);
    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, w, h);
    final RectF rectF = new RectF(rect);
    paint.setAntiAlias(true);//from  ww  w  .j av a2 s.co m
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);

    return output;
}

From source file:Main.java

public static Bitmap toThreshold(Bitmap bmpOriginal) {
    int imageWidth = bmpOriginal.getWidth();
    int imageHeight = bmpOriginal.getHeight();
    Bitmap bmpThreshold = Bitmap.createBitmap(imageWidth, imageHeight, Bitmap.Config.RGB_565);
    int[] buffer = new int[imageWidth];

    int grayVal;//from  ww  w  .  ja  va  2  s . com
    for (int row = 0; row < imageHeight; row++) {
        for (int col = 0; col < imageWidth; col++) {
            grayVal = rgbToGray(bmpOriginal.getPixel(col, row));
            if (grayVal > 125)
                buffer[col] = Color.rgb(255, 255, 255);
            else
                buffer[col] = Color.rgb(0, 0, 0);
        }
        bmpThreshold.setPixels(buffer, 0, imageWidth, 0, row, imageWidth, 1);
    }
    return bmpThreshold;
}

From source file:Main.java

public static Bitmap desaturateImage(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.5f, 1.5f, 1.5f, 0, -1, 1.5f, 1.5f, 1.5f, 0, -1, 1.5f, 1.5f, 1.5f, 0, -1,
            0, 0, 0, 1, 0 };/*  ww w .ja v  a  2  s  .  c o  m*/

    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 memoriesImage(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.393f, 0.769f, 0.189f, 0, 0, 0.349f, 0.686f, 0.168f, 0, 0, 0.272f, 0.534f,
            0.134f, 0, 0, 0, 0, 0, 1, 0 };

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

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

    return bitmap;
}