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 resizeOuterFit(Bitmap src, Rect rect) {

    float aspectRatio = Math.max((float) rect.width() / src.getWidth(),
            (float) rect.height() / src.getHeight());
    int newWidth = (int) (src.getWidth() * aspectRatio);
    int newHeight = (int) (src.getHeight() * aspectRatio);
    return Bitmap.createScaledBitmap(src, newWidth, newHeight, false);
}

From source file:Main.java

public static Bitmap flipBitmap(Bitmap src) {
    Matrix m = new Matrix();
    m.preScale(-1, 1);/*w  w w . ja  va  2 s  .c om*/
    Bitmap dst = Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), m, false);
    dst.setDensity(DisplayMetrics.DENSITY_DEFAULT);
    return dst;
}

From source file:Main.java

public static Bitmap resizeBitmap(Bitmap bitmap, int maxLength) {
    if (null == bitmap)
        return null;
    int w = bitmap.getWidth();
    int h = bitmap.getHeight();
    float scale = (float) maxLength / h;
    Matrix matrix = new Matrix();
    matrix.postScale(scale, scale);/*from   www .  j a  va  2  s .c  o  m*/
    Bitmap zoomedBitmap = Bitmap.createBitmap(bitmap, 0, 0, w, h, matrix, true);
    return zoomedBitmap;
}

From source file:Main.java

public static Bitmap getResizedBitmap(Bitmap bm, int newWidth, int newHeight) {
    int width = bm.getWidth();
    int height = bm.getHeight();
    float scaleWidth = ((float) newWidth) / width;
    float scaleHeight = ((float) newHeight) / height;

    if (scaleWidth < scaleHeight) {
        scaleHeight = scaleWidth;/*ww w  .  j  a va  2 s .  c o  m*/
    } else {
        scaleWidth = scaleHeight;
    }

    // create a matrix for the manipulation
    Matrix matrix = new Matrix();
    // resize the bit map
    matrix.postScale(scaleWidth, scaleHeight);

    // "recreate" the new bitmap
    return Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);
}

From source file:Main.java

/**
 * /*from w w w  . j ava  2 s. co  m*/
 * @return Resource's RGBA byte array
 */
public static byte[] getImageRGBA(Resources res, int resouceId) {
    Bitmap bitmap = BitmapFactory.decodeResource(res, resouceId);
    if (bitmap.getWidth() != 32 || bitmap.getHeight() != 32) {
    }
    return getImageRGBA(bitmap);
}

From source file:Main.java

/**
 * Method to get the number of bytes of the source Bitmap.
 *
 * @param source The source Bitmap./*from  w w  w  . ja v  a 2 s.c  o  m*/
 * @return The number of bytes of the source Bitmap.
 */
private static int byteSizeOf(Bitmap source) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR1) {
        return source.getRowBytes() * source.getHeight();
    } else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        return source.getByteCount();
    } else {
        return source.getAllocationByteCount();
    }
}

From source file:Main.java

private static Bitmap rotateBitmap(Bitmap bitmap, int rotate) {
    if (bitmap == null)
        return null;

    int w = bitmap.getWidth();
    int h = bitmap.getHeight();

    // Setting post rotate to 90  
    Matrix mtx = new Matrix();
    mtx.postRotate(rotate);/*from  w  w  w  .ja v  a2s  .c  o m*/
    return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true);
}

From source file:Main.java

public static byte[] bmpToByteArray2(final Bitmap bmp, final boolean needRecycle) {

    int i;// ww w .  j  a  va2  s .  c o m
    int j;
    if (bmp.getHeight() > bmp.getWidth()) {
        i = bmp.getWidth();
        j = bmp.getWidth();
    } else {
        i = bmp.getHeight();
        j = bmp.getHeight();
    }

    Bitmap localBitmap = Bitmap.createBitmap(i, j, Bitmap.Config.RGB_565);
    Canvas localCanvas = new Canvas(localBitmap);

    while (true) {
        localCanvas.drawBitmap(bmp, new Rect(0, 0, i, j), new Rect(0, 0, i, j), null);
        if (needRecycle)
            bmp.recycle();
        ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
        localBitmap.compress(Bitmap.CompressFormat.JPEG, 100, localByteArrayOutputStream);
        localBitmap.recycle();
        byte[] arrayOfByte = localByteArrayOutputStream.toByteArray();
        try {
            localByteArrayOutputStream.close();
            return arrayOfByte;
        } catch (Exception e) {
            //F.out(e);
        }
        i = bmp.getHeight();
        j = bmp.getHeight();
    }
}

From source file:Main.java

public static Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth) {
    int width = bm.getWidth();
    int height = bm.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(bm, 0, 0, width, height, matrix, false);

    return resizedBitmap;
}

From source file:Main.java

/** Return a bitmap identical to src with rounded corners. */
public static final Bitmap roundCornersRGB888(Bitmap src, int roundPixles) {
    final Bitmap output = Bitmap.createBitmap(src.getWidth(), src.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    // TODO: document what is special about this color
    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, src.getWidth(), src.getHeight());
    final RectF rectF = new RectF(rect);

    paint.setAntiAlias(true);/*  w w  w  .jav  a2s.  c o m*/
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPixles, roundPixles, paint);

    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(src, 0, 0, paint);

    return output;
}