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 getRotatedBitmap(Bitmap mBitmap, float degrees) {
    int width = mBitmap.getWidth();
    int height = mBitmap.getHeight();

    Matrix matrix = new Matrix();
    matrix.postRotate(degrees);//w  w  w  .  j  a  va  2 s.  c o  m
    Bitmap mRotateBitmap = Bitmap.createBitmap(mBitmap, 0, 0, width, height, matrix, true);

    return mRotateBitmap;
}

From source file:Main.java

public static Bitmap scaleBitmap(int maxWidth, int maxHeight, Bitmap bitmap) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    float scale = 1;

    if (height > width) {
        if (height > maxHeight) {
            scale = (float) maxHeight / (float) height;
        }//  w ww  .j  a v  a 2 s .  c  o  m
    } else {
        if (width > maxWidth) {
            scale = (float) maxWidth / (float) width;
        }
    }

    width = (int) (width * scale);
    height = (int) (height * scale);

    return Bitmap.createScaledBitmap(bitmap, width, height, false);
}

From source file:Main.java

static public Bitmap scaleToFitHeight(Bitmap b, int height) {
    Log.e("Hieght", height + "");
    float factor = height / (float) b.getHeight();

    return Bitmap.createScaledBitmap(b, (int) (b.getWidth() * factor), height, false);

}

From source file:Main.java

public static Bitmap crop(Bitmap srcBmp, int side) {

    Bitmap dstBmp;/* w  w  w  . jav  a  2s  .c  om*/

    if (srcBmp.getWidth() >= srcBmp.getHeight()) {

        dstBmp = Bitmap.createBitmap(srcBmp, srcBmp.getWidth() / 2 - srcBmp.getHeight() / 2, 0,
                srcBmp.getHeight(), srcBmp.getHeight());

    } else {

        dstBmp = Bitmap.createBitmap(srcBmp, 0, srcBmp.getHeight() / 2 - srcBmp.getWidth() / 2,
                srcBmp.getWidth(), srcBmp.getWidth());
    }

    return Bitmap.createScaledBitmap(dstBmp, side, side, true);
}

From source file:Main.java

private static Bitmap createBitmap(Bitmap source, Matrix m) {
    return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), m, true);
}

From source file:Main.java

public static Bitmap blurBitmap(Context context, Bitmap bitmap) {
    Bitmap outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    RenderScript rs = RenderScript.create(context);
    ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
    Allocation allIn = Allocation.createFromBitmap(rs, bitmap);
    Allocation allOut = Allocation.createFromBitmap(rs, outBitmap);
    blurScript.setRadius(8f);/*from  ww  w  . jav a  2  s.  com*/
    blurScript.setInput(allIn);
    blurScript.forEach(allOut);
    allOut.copyTo(outBitmap);
    bitmap.recycle();
    rs.destroy();
    return outBitmap;
}

From source file:Main.java

/**
 * reversal bitmap at left-right/*  w w  w .j av a  2  s.  c o m*/
 * 
 * @param originalImage
 * @return the bitmap after reversal
 */
public static Bitmap createReversal(Bitmap originalImage) {
    int width = originalImage.getWidth();
    int height = originalImage.getHeight();

    Matrix matrix = new Matrix();
    matrix.preScale(-1.0f, 1.0f);

    return Bitmap.createBitmap(originalImage, 0, 0, width, height, matrix, false);
}

From source file:Main.java

public static int[] bitmapToIntArray(Bitmap bitmap) {
    final int bitmapWidth = bitmap.getWidth();
    final int bitmapHeight = bitmap.getHeight();

    int[] colors = new int[bitmapWidth * bitmapHeight];
    bitmap.getPixels(colors, 0, bitmapWidth, 0, 0, bitmapWidth, bitmapHeight);

    return colors;
}

From source file:Main.java

static public Bitmap scaleBitmapToPx(Context context, Bitmap bitmap, float dpX, float dpY) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    return scaleBitmap(bitmap, dpX / width, dpY / height);
}

From source file:Main.java

private static Bitmap toGrayscale(Bitmap bmpOriginal) {
    int width, height;
    height = bmpOriginal.getHeight();
    width = bmpOriginal.getWidth();//from  ww w  .  jav a2 s.  c  o m

    Bitmap bmpGrayscale = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(bmpGrayscale);
    Paint paint = new Paint();
    ColorMatrix cm = new ColorMatrix();
    cm.setSaturation(0);

    ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm);
    paint.setColorFilter(f);
    c.drawBitmap(bmpOriginal, 0, 0, paint);
    return bmpGrayscale;
}