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 joinBitmaps(Bitmap first, Bitmap second) {
    Bitmap result = Bitmap.createBitmap(first.getWidth(), first.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(result);
    Paint bitmapPaint = new Paint();
    if (second.getWidth() != first.getWidth() && second.getHeight() != first.getHeight()) {
        second = createScaledToFillBitmap(second, first.getWidth(), first.getHeight());
    }//from w  w  w .  j a va  2 s  .  c  om

    canvas.drawBitmap(first, 0, 0, bitmapPaint);
    canvas.drawBitmap(second, 0, 0, bitmapPaint);

    return result;
}

From source file:Main.java

/**
 * Method to split an image vertically into a List
 * composed by {@code piecesNum} of Bitmaps.
 *
 * @param source    The source Bitmap./*www .  j a va  2s.  co  m*/
 * @param piecesNum int that represents the number of pieces.
 * @return The List of Bitmap's pieces.
 */
public static List<Bitmap> splitImageVertically(Bitmap source, int piecesNum) {
    List<Bitmap> pieces = new ArrayList<>();
    int height = source.getHeight() / piecesNum;
    int start = 0;
    for (int i = 0; i < piecesNum; i++) {
        Bitmap pieceBitmap = Bitmap.createBitmap(source, 0, start, source.getWidth() - 1, height - 1);
        pieces.add(pieceBitmap);
        start = (source.getHeight() / piecesNum) * (i + 1);
    }
    return pieces;
}

From source file:Main.java

public static Bitmap imageScale(Bitmap bitmap, int dst_w, int dst_h) {
    int src_w = bitmap.getWidth();
    int src_h = bitmap.getHeight();
    float scale_w = ((float) dst_w) / src_w;
    float scale_h = ((float) dst_h) / src_h;
    Matrix matrix = new Matrix();
    matrix.postScale(scale_w, scale_h);//from w  ww  .  j av a 2s .co  m
    Bitmap dstbmp = Bitmap.createBitmap(bitmap, 0, 0, src_w, src_h, matrix, true);
    return dstbmp;
}

From source file:Main.java

public static Bitmap getResizedBitmap(Bitmap bitmap, int newHeight, int newWidth) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    float scaleWidth = ((float) newWidth) / width;
    float scaleHeight = ((float) newHeight) / height;
    // CREATE A MATRIX FOR THE MANIPULATION
    Matrix matrix = new Matrix();
    // RESIZE THE BIT MAP
    matrix.postScale(scaleWidth, scaleHeight);
    // RECREATE THE NEW BITMAP
    Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, false);

    return resizedBitmap;
}

From source file:Main.java

public static Bitmap getCircleBitmap(Bitmap bitmap) {
    final Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(output);

    final int color = Color.WHITE;
    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   ww  w .j  ava  2 s.  c  o  m
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawOval(rectF, paint);

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

    bitmap.recycle();

    return output;
}

From source file:Main.java

/**
 * Find the difference between two bitmaps using average of per-pixel differences.
 *
 * @param a first {@link android.graphics.Bitmap}.
 * @param b second {@link android.graphics.Bitmap}.
 * @return the difference.//from w  ww .j  av  a  2s .c o  m
 */
public static double calcDifferenceMetric(Bitmap a, Bitmap b) {
    if (a.getWidth() != b.getWidth() || a.getHeight() != b.getHeight()) {
        throw new IllegalArgumentException("Bitmap dimensions for arguments do not match a=" + a.getWidth()
                + "x" + a.getHeight() + ", b=" + b.getWidth() + "x" + b.getHeight());
    }
    // TODO: Optimize this in renderscript to avoid copy.
    int[] aPixels = new int[a.getHeight() * a.getWidth()];
    int[] bPixels = new int[aPixels.length];
    a.getPixels(aPixels, /*offset*/0, /*stride*/a.getWidth(), /*x*/
            0, /*y*/0, a.getWidth(), a.getHeight());
    b.getPixels(bPixels, /*offset*/0, /*stride*/b.getWidth(), /*x*/
            0, /*y*/0, b.getWidth(), b.getHeight());
    double diff = 0;
    for (int i = 0; i < aPixels.length; i++) {
        int aPix = aPixels[i];
        int bPix = bPixels[i];

        diff += Math.abs(Color.red(aPix) - Color.red(bPix)); // red
        diff += Math.abs(Color.green(aPix) - Color.green(bPix)); // green
        diff += Math.abs(Color.blue(aPix) - Color.blue(bPix)); // blue
    }
    diff /= (aPixels.length * 3);
    return diff;
}

From source file:Main.java

public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int pixels) {
    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 = pixels;

    paint.setAntiAlias(true);//  ww w .  j av a 2 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

public static Bitmap doColorFilter(Bitmap src, double red, double green, double blue) {
    int w = src.getWidth();
    int h = src.getHeight();

    Bitmap bmOut = Bitmap.createBitmap(w, h, src.getConfig());
    int A, R, G, B, pixel;
    for (int x = 0; x < w; x++) {
        for (int y = 0; y < h; y++) {
            pixel = src.getPixel(x, y);/*from   w  ww  . j  av  a2  s . c o  m*/
            A = Color.alpha(pixel);
            R = (int) (Color.red(pixel) * red);
            G = (int) (Color.green(pixel) * green);
            B = (int) (Color.blue(pixel) * blue);
            bmOut.setPixel(x, y, Color.argb(A, R, G, B));
        }
    }
    return bmOut;
}

From source file:Main.java

public static Bitmap overlay(Bitmap bmp1, Bitmap bmp2, float left, float top) {
    Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig());
    Canvas canvas = new Canvas(bmOverlay);
    canvas.drawBitmap(bmp1, new Matrix(), null);
    canvas.drawBitmap(bmp2, left, top, null);
    return bmOverlay;
}

From source file:Main.java

public static Bitmap handleImageOldPhoto(Bitmap bm) {
    int width = bm.getWidth();
    int height = bm.getHeight();
    int color;//  w  w w .j a v a  2  s  .c  om
    int r, g, b, a;
    Bitmap bmp = Bitmap.createBitmap(bm.getWidth(), bm.getHeight(), Bitmap.Config.ARGB_8888);
    int[] oldPx = new int[width * height];
    int[] newPx = new int[width * height];
    bm.getPixels(oldPx, 0, width, 0, 0, width, height);
    for (int i = 0; i < width * height; i++) {
        color = oldPx[i];
        r = Color.red(color);
        g = Color.green(color);
        b = Color.blue(color);
        a = Color.alpha(color);

        r = (int) (0.393 * r + 0.769 * g + 0.189 * b);
        g = (int) (0.349 * r + 0.686 * g + 0.168 * b);
        b = (int) (0.272 * r + 0.534 * g + 0.131 * b);
        if (r > 255) {
            r = 255;
        }
        if (g > 255) {
            g = 255;
        }
        if (b > 255) {
            b = 255;
        }
        newPx[i] = Color.argb(a, r, g, b);
    }
    bmp.setPixels(newPx, 0, width, 0, 0, width, height);
    return bmp;

}