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 getRoundedCornerBitmap(Bitmap bitmap) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);
    final float roundPx = 12;

    paint.setAntiAlias(true);/*from w  ww  .  ja va2 s . c  o  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 createResizedBitmap(Bitmap srcBit, int newWidth, int newHeight) {
    int width = srcBit.getWidth();
    int height = srcBit.getHeight();

    // calculate the scale - in this case = 0.4f
    float scaleWidth = ((float) newWidth) / width;
    float scaleHeight = ((float) newHeight) / height;

    Matrix matrix = new Matrix();
    matrix.postScale(scaleWidth, scaleHeight);
    Bitmap resizedBitmap = Bitmap.createBitmap(srcBit, 0, 0, width, height, matrix, true);

    width = resizedBitmap.getWidth();//from w ww  .  ja v a2s. c o  m
    height = resizedBitmap.getHeight();

    Log.i("ImageResize",
            "Image Resize Result : " + Boolean.toString((newHeight == height) && (newWidth == width)));
    return resizedBitmap;
}

From source file:Main.java

public static byte[] bmp2bytesStream(Bitmap bitmap) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    if (width % 8 != 0) {
        int adjustWidth = width + (8 - width % 8);
        final Bitmap.Config config = Bitmap.Config.ARGB_8888;
        Bitmap whiteBgBitmap = Bitmap.createBitmap(adjustWidth, height, config);
        Canvas canvas = new Canvas(whiteBgBitmap);
        canvas.drawColor(Color.WHITE);
        canvas.drawBitmap(bitmap, 0, 0, null);

        bitmap = whiteBgBitmap;/*www  . ja  v a  2  s.co  m*/
        width = bitmap.getWidth();
    }
    int[] pixels = new int[width * height];
    bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
    byte[] image = new byte[width * height];
    final byte WHITE = 0, BLACK = 1;
    for (int i = 0; i < pixels.length; i++) {
        image[i] = (pixels[i] != 0xFFFFFFFF) ? BLACK : WHITE;
    }
    final int COL = width + width % 2;
    byte[] row = new byte[COL];
    byte[] res = new byte[COL / 8 * height];
    for (int i = 0, dex = 0, num = 0; i < height; ++i) {
        System.arraycopy(image, i * width, row, 0, width);
        for (byte e : row) {
            res[dex] += e << (7 - num++);
            num = 8 == num ? 0 : num;
            dex = 0 == num ? dex + 1 : dex;
        }
    }
    return res;
}

From source file:Main.java

public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int radiusPixel) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);

    Canvas canvas = new Canvas(output);

    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);
    final float roundPx = radiusPixel;

    paint.setAntiAlias(true);/*from  w w w . j a  v  a2 s .c  om*/
    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

/**
 * This method takes a square bitmap and clips it into a circle
 *
 * @param bitmap : the image to clip//  w ww .  j av a  2 s  . c o m
 * @return the clipped bitmap
 */
public static Bitmap getCroppedBitmap(Bitmap bitmap) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    // canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
    canvas.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2, bitmap.getWidth() / 2, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.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 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 byte[] getGrayscale(Bitmap bitmap) {
    if (bitmap == null)
        return null;
    byte[] ret = new byte[bitmap.getWidth() * bitmap.getHeight()];
    for (int j = 0; j < bitmap.getHeight(); ++j)
        for (int i = 0; i < bitmap.getWidth(); ++i) {
            int pixel = bitmap.getPixel(i, j);
            int red = ((pixel & 0x00FF0000) >> 16);
            int green = ((pixel & 0x0000FF00) >> 8);
            int blue = pixel & 0x000000FF;
            ret[j * bitmap.getWidth() + i] = (byte) ((299 * red + 587 * green + 114 * blue) / 1000);
        }/*from w w  w .j a  v a 2 s. c o m*/
    return ret;
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
public static int sizeOf(Bitmap data) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR1) {
        return data.getRowBytes() * data.getHeight();
    } else {/*  w w  w .  j a  v a  2s  .  co m*/
        return data.getByteCount();
    }
}

From source file:Main.java

public static Bitmap addWhiteBorder(Bitmap bmp, int borderSize) {
    Bitmap bmpWithBorder = Bitmap.createBitmap(bmp.getWidth() + borderSize * 2,
            bmp.getHeight() + borderSize * 2, bmp.getConfig());
    Canvas canvas = new Canvas(bmpWithBorder);
    canvas.drawColor(Color.WHITE);
    canvas.drawBitmap(bmp, borderSize, borderSize, null);
    return bmpWithBorder;
}

From source file:Main.java

/**
 * ATTENTION: DON'T USE THIS METHOD BECAUSE IT HAS BAD PERFORMANCES.
 *
 * @param source The original Bitmap.//from  w w  w .  ja va 2  s. c  o  m
 * @param color  Color to overlay.
 * @return the result image.
 */
@Deprecated
private static Bitmap overlayColor(Bitmap source, int color) {
    Bitmap newBitmap = Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight());
    Bitmap mutableBitmap = newBitmap.copy(Bitmap.Config.ARGB_8888, true);
    Canvas canvas = new Canvas(mutableBitmap);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    ColorFilter filter = new LightingColorFilter(color, 1);
    paint.setColorFilter(filter);
    canvas.drawBitmap(mutableBitmap, 0, 0, paint);
    return mutableBitmap;
}