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

private static boolean isEmptyBitmap(Bitmap src) {
    return src == null || src.getWidth() == 0 || src.getHeight() == 0;
}

From source file:Main.java

public static int getPixelsCount(Bitmap bitmap) {
    int hlen = bitmap.getWidth(), vlen = bitmap.getHeight();
    int toReturn = 0;
    for (int i = 0; i < vlen; i++) {
        for (int j = 0; j < hlen; j++) {
            if ((bitmap.getPixel(j, i) & 0xff) > 0) {
                toReturn++;/*from   w w  w  .  j ava2 s. co m*/
            }
        }
    }

    return toReturn;
}

From source file:Main.java

private static void checkBitmapCache() {
    if (bitmapCache == null) {
        bitmapCache = new LruCache<String, Bitmap>((int) Runtime.getRuntime().maxMemory() / 8) {
            @Override/*from  w  w w  .j a v  a  2s . c o  m*/
            protected int sizeOf(String key, Bitmap bitmap) {
                return bitmap.getRowBytes() * bitmap.getHeight();
            }
        };
    }
}

From source file:Main.java

/**
 * convert Bitmap to round corner//from   w w w .jav  a2 s.  c om
 *
 * @param bitmap
 * @return
 */
public static Bitmap toRoundCorner(Bitmap bitmap) {
    int height = bitmap.getHeight();
    int width = bitmap.getHeight();
    Bitmap output = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(output);

    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, width, height);

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(0xff424242);
    //paint.setColor(Color.TRANSPARENT);
    canvas.drawCircle(width / 2, height / 2, width / 2, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    return output;
}

From source file:Main.java

/**
 * @param bitmap//  w  ww  .  j  av a 2  s.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 rotateBmp(Bitmap bmp, int degree) {
    int w = bmp.getWidth();
    int h = bmp.getHeight();
    Matrix mtx = new Matrix();
    mtx.postRotate(degree);/*from  w  ww  .  jav a2  s . c om*/
    Bitmap rotatedBMP = Bitmap.createBitmap(bmp, 0, 0, w, h, mtx, true);
    return rotatedBMP;
}

From source file:Main.java

public static Bitmap getImageCrop(Bitmap bitmap) {
    int w = bitmap.getWidth();
    int h = bitmap.getHeight();

    int wh = w > h ? h : w;

    int retX = w > h ? (w - h) / 2 : 0;
    int retY = w > h ? 0 : (h - w) / 2;

    return Bitmap.createBitmap(bitmap, retX, retY, wh, wh, null, false);
}

From source file:Main.java

public static int[] getRGBSum(Bitmap bitmap) {
    int height = bitmap.getHeight();
    int width = bitmap.getWidth();
    int[] pixels = new int[(width * height)];
    bitmap.getPixels(pixels, 0, width, 0, 0, width, height);

    int[] sum = new int[3];
    for (int YY = 0; YY < width; ++YY) {
        for (int XX = 0; XX < height; ++XX) {
            int bitmapColor = pixels[(YY + XX * width)];
            sum[0] += Color.red(bitmapColor);
            sum[1] += Color.green(bitmapColor);
            sum[2] += Color.blue(bitmapColor);
        }//from ww  w . j a v a 2  s  . co  m
    }

    return sum;
}

From source file:Main.java

/**
 * Convert bitmap to the grayscale/* w w w  . j a v  a  2s  . c  om*/
 * http://androidsnippets.com/convert-bitmap-to-grayscale
 *
 * @param bmpOriginal Original bitmap
 * @return Grayscale bitmap
 */
public static Bitmap toGrayscale(Bitmap bmpOriginal) {
    final int height = bmpOriginal.getHeight();
    final int width = bmpOriginal.getWidth();

    final Bitmap bmpGrayscale = Bitmap.createBitmap(width, height, Config.ARGB_8888);
    final Canvas c = new Canvas(bmpGrayscale);
    final Paint paint = new Paint();
    final ColorMatrix cm = new ColorMatrix();
    cm.setSaturation(0);
    final ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm);
    paint.setColorFilter(f);
    c.drawBitmap(bmpOriginal, 0, 0, paint);
    return bmpGrayscale;
}

From source file:Main.java

public static Bitmap convertToAlphaMask(Bitmap b) {
    Bitmap a = Bitmap.createBitmap(b.getWidth(), b.getHeight(), Bitmap.Config.ALPHA_8);
    Canvas c = new Canvas(a);
    c.drawBitmap(b, 0.0f, 0.0f, null);/*from w ww . j  av  a  2s.c om*/

    return a;
}