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, float radius) {
    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);

    paint.setAntiAlias(true);/*from www.  ja va 2s. co  m*/
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, radius, radius, paint);

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

    return output;
}

From source file:Main.java

public static Bitmap toRoundCorner(Bitmap bitmap, int pixels, PorterDuff.Mode mode) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(output);
    final int color = 0xffffffff;
    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 = pixels;
    paint.setAntiAlias(true);/*from w  ww  . j av a2s  .  com*/
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
    paint.setXfermode(new PorterDuffXfermode(mode));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    return output;
}

From source file:Main.java

public static Bitmap flip(Bitmap src) {
    Matrix m = new Matrix();
    m.preScale(-1, 1);/*from  w w  w.j  a v a 2s  .  c o  m*/
    Bitmap dst = Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), m, false);
    return dst;
}

From source file:Main.java

/**
 * TODO doc/*from  w ww  . j a v a 2s  .c  o  m*/
 *
 * @param data
 * @return
 */
private static int byteSizeOf(Bitmap data) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR1) {
        return data.getRowBytes() * data.getHeight();
    } else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        return data.getByteCount();
    } else {
        return data.getAllocationByteCount();
    }
}

From source file:Main.java

public static Bitmap flipBitmap(Bitmap bm) {
    Matrix matrix = new Matrix();
    matrix.postRotate(90);// ww w.  ja v a  2  s  .co  m
    int width = bm.getWidth();
    int height = bm.getHeight();
    bm = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, true);
    return bm;
}

From source file:Main.java

public static Bitmap nostalgic(Bitmap bitmap) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    Bitmap newBitmap = Bitmap.createBitmap(width, height, Config.RGB_565);
    int pixColor = 0;
    int pixR = 0;
    int pixG = 0;
    int pixB = 0;
    int newR = 0;
    int newG = 0;
    int newB = 0;
    int[] pixels = new int[width * height];
    bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
    for (int i = 0; i < height; i++) {
        for (int k = 0; k < width; k++) {
            pixColor = pixels[width * i + k];
            pixR = Color.red(pixColor);
            pixG = Color.green(pixColor);
            pixB = Color.blue(pixColor);
            newR = (int) (0.393 * pixR + 0.769 * pixG + 0.189 * pixB);
            newG = (int) (0.349 * pixR + 0.686 * pixG + 0.168 * pixB);
            newB = (int) (0.272 * pixR + 0.534 * pixG + 0.131 * pixB);
            int newColor = Color.argb(255, newR > 255 ? 255 : newR, newG > 255 ? 255 : newG,
                    newB > 255 ? 255 : newB);
            pixels[width * i + k] = newColor;
        }/*  w w w. j a  v  a 2s . c o  m*/
    }
    newBitmap.setPixels(pixels, 0, width, 0, 0, width, height);
    return newBitmap;
}

From source file:Main.java

public static Bitmap scaleToFitWidth(Bitmap bitmap, int i) {
    return Bitmap.createScaledBitmap(bitmap, i,
            (int) (((float) i / (float) bitmap.getWidth()) * (float) bitmap.getHeight()), false);
}

From source file:Main.java

private static Bitmap rotate(Bitmap result, int rotation) {
    Matrix matrix = new Matrix();
    matrix.setRotate(rotation, (float) result.getWidth() / 2, (float) result.getHeight() / 2);

    return Bitmap.createBitmap(result, 0, 0, result.getWidth(), result.getHeight(), matrix, true);
}

From source file:Main.java

public static Bitmap getCroppedBitmap(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());

    paint.setAntiAlias(true);// w  w w . j a  v  a  2 s  . co m
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    if (bitmap.getHeight() > bitmap.getWidth()) {
        // Dikey
        canvas.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2, bitmap.getWidth() / 2, paint);
    } else {
        // Yatay
        canvas.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2, bitmap.getHeight() / 2, paint);
    }

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

    if (bitmap.getHeight() > bitmap.getWidth()) {
        // Dikey
        output = Bitmap.createBitmap(output, 0, output.getHeight() / 2 - output.getWidth() / 2,
                output.getWidth(), output.getWidth());
    } else {
        // Yatay
        output = Bitmap.createBitmap(output, output.getWidth() / 2 - output.getHeight() / 2, 0,
                output.getHeight(), output.getHeight());
    }

    return output;
}

From source file:Main.java

public static Bitmap get_circular_bitmap(Bitmap bitmap) {
    Bitmap output;/*from ww  w .ja v a2s. c o m*/

    if (bitmap.getWidth() > bitmap.getHeight()) {
        output = Bitmap.createBitmap(bitmap.getHeight(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    } else {
        output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getWidth(), 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());

    float r = 0;

    if (bitmap.getWidth() > bitmap.getHeight()) {
        r = bitmap.getHeight() / 2;
    } else {
        r = bitmap.getWidth() / 2;
    }

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawCircle(r, r, r, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);

    return output;
}