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 int getImageHeight(final Context context, final int drawable) {
    int bg_height = 0;
    Bitmap bmp = BitmapFactory.decodeResource(context.getResources(), drawable);
    bg_height = bmp.getHeight();
    bmp.recycle();/*from www .j a v  a2 s.c o  m*/
    return bg_height;
}

From source file:Main.java

public static Bitmap getFixedBitmap(Bitmap bm, int w, int h, boolean filter) {
    int width = bm.getWidth();
    int height = bm.getHeight();
    Matrix matrix = new Matrix();
    matrix.postScale((float) w / width, (float) h / height);
    return Bitmap.createBitmap(bm, 0, 0, width, height, matrix, filter);
}

From source file:Main.java

public static boolean hasTransparentCorners(Bitmap bitmap) {
    int width = bitmap.getWidth() - 1;
    int height = bitmap.getHeight() - 1;
    return bitmap.getPixel(0, 0) == Color.TRANSPARENT || bitmap.getPixel(width, 0) == Color.TRANSPARENT
            || bitmap.getPixel(0, height) == Color.TRANSPARENT
            || bitmap.getPixel(width, height) == Color.TRANSPARENT;
}

From source file:Main.java

public static float compareBitmaps(Bitmap a, Bitmap b) {
    int found = 0;

    for (int y = 0; y < a.getHeight(); y++) {
        for (int x = 0; x < a.getWidth(); x++) {
            if (a.getPixel(x, y) == a.getPixel(x, y)) {
                found++;/* w  w  w .  jav  a 2 s.  c o  m*/
            }
        }
    }

    return found / (float) (a.getWidth() * a.getHeight());
}

From source file:Main.java

public static Bitmap createScaledToFillBitmap(Bitmap bitmap, int reqWidth, int reqHeight) {
    final int height = bitmap.getHeight();
    final int width = bitmap.getWidth();

    float widthScaleF = (float) width / (float) reqWidth;
    float heightScaleF = (float) height / (float) reqHeight;
    if (widthScaleF < heightScaleF) {
        return Bitmap.createScaledBitmap(bitmap, reqWidth, (int) (height / widthScaleF), true);
    } else {//from   ww  w  .jav a2s .  c  om
        return Bitmap.createScaledBitmap(bitmap, (int) (width / heightScaleF), reqHeight, true);
    }
}

From source file:Main.java

public static final Bitmap grey(Bitmap bitmap) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();

    Bitmap faceIconGreyBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(faceIconGreyBitmap);
    Paint paint = new Paint();
    ColorMatrix colorMatrix = new ColorMatrix();
    colorMatrix.setSaturation(0);// ww  w . j a va2  s. c  o  m
    ColorMatrixColorFilter colorMatrixFilter = new ColorMatrixColorFilter(colorMatrix);
    paint.setColorFilter(colorMatrixFilter);
    canvas.drawBitmap(bitmap, 0, 0, paint);
    return faceIconGreyBitmap;
}

From source file:Main.java

/** Returns a scaled version of the given Bitmap. One of the returned Bitmap's width and height will be equal to size, and the other
 * dimension will be equal or less./*  w w  w.ja  v  a2 s .c  om*/
 */
public static Bitmap createScaledBitmap(Bitmap bitmap, int size) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    int scaledWidth = size, scaledHeight = size;
    if (height < width) {
        scaledHeight = (int) (size * 1.0f * height / width);
    } else if (width < height) {
        scaledWidth = (int) (size * 1.0f * width / height);
    }
    Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap, scaledWidth, scaledHeight, false);
    return scaledBitmap;
}

From source file:Main.java

public static Bitmap scaleBitmap(Bitmap srcBitmap, int newSize) {
    int w = srcBitmap.getWidth();
    int h = srcBitmap.getHeight();

    // Determine the scaling required to get desired result.
    float scaleW = newSize / (float) w;
    float scaleH = newSize / (float) h;

    Matrix matrix = new Matrix();
    matrix.postScale(scaleW, scaleH);/*  w  w w .ja va2  s  .  c om*/

    return Bitmap.createBitmap(srcBitmap, 0, 0, w, h, matrix, false);
}

From source file:Main.java

public static Bitmap PicZoom(Bitmap bmp, int width, int height) {
    int bmpWidth = bmp.getWidth();
    int bmpHeght = bmp.getHeight();
    Matrix matrix = new Matrix();
    matrix.postScale((float) width / bmpWidth, (float) height / bmpHeght);
    return Bitmap.createBitmap(bmp, 0, 0, bmpWidth, bmpHeght, matrix, true);
}

From source file:Main.java

public static Bitmap zoomBitmap(Bitmap bitmap, float scale) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    Log.e("ss", "width=" + width);
    Log.e("ss", "height=" + height);
    Matrix matrix = new Matrix();
    //float scaleWidht = ((float)w / width);
    //float scaleHeight = ((float)h / height);
    matrix.postScale(scale, scale);/*from   ww w  . ja v a 2  s .  c om*/
    Bitmap newbmp = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
    return newbmp;
}