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 boolean shouldScaleDownBitmap(Context context, Bitmap bitmap) {
    if (context != null && bitmap != null && bitmap.getWidth() > 0 && bitmap.getHeight() > 0) {
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();
        DisplayMetrics metrics = new DisplayMetrics();
        display.getMetrics(metrics);//w  w w  . j a v  a 2s .  com
        int width = metrics.widthPixels;
        int height = metrics.heightPixels;
        return ((width != 0 && width / bitmap.getWidth() < 1)
                || (height != 0 && height / bitmap.getHeight() < 1));
    }
    return false;
}

From source file:Main.java

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

    Matrix matrix = new Matrix();
    matrix.postScale(scaleWidth, scaleHeight);

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

From source file:Main.java

/**
 * Fill the hole in the image (version 1)
 */// www. ja va 2s .co  m
public static void fillHole1(Bitmap bmp) {

    for (int j = 1; j < bmp.getWidth() - 1; j++) {
        for (int i = 1; i < bmp.getHeight(); i++) {
            if ((bmp.getPixel(i, j) == Color.TRANSPARENT) && (bmp.getPixel(i, j + 1) != Color.TRANSPARENT)) {
                bmp.setPixel(i, j, bmp.getPixel(i, j + 1)); // set to the right-next pixel
            }
        }
    }
}

From source file:Main.java

public static Bitmap getRoundedImage(Bitmap bitmap) {
    Bitmap circleBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);

    BitmapShader shader = new BitmapShader(bitmap, TileMode.CLAMP, TileMode.CLAMP);
    Paint paint = new Paint();
    paint.setShader(shader);/*from  w w  w . j  a  va 2s.  c o m*/

    Canvas c = new Canvas(circleBitmap);
    c.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2, bitmap.getWidth() / 2, paint);

    return circleBitmap;
}

From source file:Main.java

public static Bitmap[] splitBitmap(Bitmap pic, int row, int col) {
    int tileWidth = pic.getWidth() / col;
    int tileHeight = pic.getHeight() / row;

    Bitmap[] tiles = new Bitmap[row * col];
    for (int r = 0; r < row; r++) {
        for (int c = 0; c < col; c++) {
            tiles[r * col + c] = Bitmap.createBitmap(pic, c * tileWidth, r * tileHeight, tileWidth, tileHeight);
        }/*from   ww  w. j  a  v a2s  . co m*/
    }
    return tiles;
}

From source file:Main.java

public static Bitmap scale(Bitmap b, float scale) {
    Bitmap res = Bitmap.createBitmap((int) (b.getWidth() * scale + .5f), (int) (b.getHeight() * scale + .5f),
            b.getConfig());/*  w  w  w .  j av  a 2  s . co m*/
    Canvas c = new Canvas(res);
    c.scale(scale, scale);
    c.drawBitmap(b, 0, 0, scalePaint);
    return res;
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static Bitmap blurBitmap(Bitmap bitmap, Context context) {
    int width = bitmap.getWidth(), height = bitmap.getHeight();
    Bitmap b = Bitmap.createScaledBitmap(
            Bitmap.createScaledBitmap(bitmap, (int) (width / SCALE_RATIO), (int) (height / SCALE_RATIO), false),
            width, height, false);/* w  w  w  .  jav  a 2  s.c om*/
    return blurBitmap(b, DEFAULT_BLUR_RADIUS, context);
}

From source file:Main.java

public static Bitmap setupFrame(Bitmap bitmap, int width, int color) {
    if (bitmap.getWidth() <= width * 2 || bitmap.getHeight() <= width * 2) {
        return bitmap;
    }// w  ww. jav a 2 s .  co  m

    Bitmap bp = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);

    Canvas canvas = new Canvas(bp);
    canvas.drawBitmap(bitmap, 0, 0, new Paint());
    Paint paint = new Paint();
    paint.setColor(color);
    paint.setStrokeWidth(width);
    paint.setStyle(Style.STROKE);
    canvas.drawRect(0, 0, canvas.getWidth() - width, canvas.getHeight() - width, paint);

    bitmap.recycle();
    return bp;
}

From source file:Main.java

public static Bitmap getFullScreenBitmap(Bitmap bitmap, int wScale, int hScale) {
    int dstWidth = bitmap.getWidth() * wScale;
    int dstHeight = bitmap.getHeight() * hScale;
    Bitmap result = Bitmap.createScaledBitmap(bitmap, dstWidth, dstHeight, false);
    return result;
}

From source file:Main.java

public static Bitmap scaleBitmap(Bitmap bitmap, float scale) {
    return resizeBitmap(bitmap, (int) (bitmap.getWidth() * scale), (int) (bitmap.getHeight() * scale));
}