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 bitmapZoomByScale(Bitmap srcBitmap, float scaleWidth, float scaleHeight) {
    int srcWidth = srcBitmap.getWidth();
    int srcHeight = srcBitmap.getHeight();
    Matrix matrix = new Matrix();

    matrix.postScale(scaleWidth, scaleHeight);
    Bitmap resizedBitmap = Bitmap.createBitmap(srcBitmap, 0, 0, srcWidth, srcHeight, matrix, true);
    if (resizedBitmap != null) {
        srcBitmap = null;/*  w  ww  .  java 2s. co m*/
        return resizedBitmap;
    } else {
        return srcBitmap;
    }
}

From source file:Main.java

/**
 * Create a rounded corner bitmap from current bitmap
 *
 * @param bitmap/*w  w w. ja v  a2 s. c  o m*/
 * @return
 */
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) {
    try {
        Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
        Canvas canvas = new Canvas(output);
        final Paint paint = new Paint();
        final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
        final RectF rectF = new RectF(new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()));
        final float roundPx = 50;
        paint.setAntiAlias(true);
        canvas.drawARGB(0, 0, 0, 0);
        paint.setColor(Color.BLACK);
        canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));

        final Rect src = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());

        canvas.drawBitmap(bitmap, src, rect, paint);
        return output;
    } catch (Exception e) {
        return bitmap;
    }
}

From source file:Main.java

public static Bitmap zoom(Bitmap source, float wf, float hf) {
    Matrix matrix = new Matrix();
    float sx = wf / source.getWidth();
    float sy = hf / source.getHeight();
    matrix.postScale(sx, sy);//from  w w  w  .  j a  v  a  2 s  . c  o m
    return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true);
}

From source file:com.BeeFramework.Utils.Utils.java

public static Bitmap scaleBitmap(Bitmap bm, int pixel) {
    int srcHeight = bm.getHeight();
    int srcWidth = bm.getWidth();

    if (srcHeight > pixel || srcWidth > pixel) {
        float scale_y = 0;
        float scale_x = 0;
        if (srcHeight > srcWidth) {
            scale_y = ((float) pixel) / srcHeight;
            scale_x = scale_y;//from   ww w  .  j a  v a 2  s  .  c  o m
        } else {
            scale_x = ((float) pixel) / srcWidth;
            scale_y = scale_x;
        }

        Matrix matrix = new Matrix();
        matrix.postScale(scale_x, scale_y);
        Bitmap dstbmp = Bitmap.createBitmap(bm, 0, 0, srcWidth, srcHeight, matrix, true);
        return dstbmp;
    } else {
        return Bitmap.createBitmap(bm);
    }
}

From source file:Main.java

public static Bitmap zoomBitmap(Bitmap bitmap, float w, float h) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    Matrix matrix = new Matrix();
    float scaleW = ((float) w / width);
    float scaleH = ((float) h / height);
    matrix.postScale(scaleW, scaleH);/*from  w w w  .  ja  va2 s .com*/
    Bitmap newBmp = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);

    return newBmp;
}

From source file:Main.java

public static Bitmap roundCorners(final Bitmap source, final float radius) {
    int width = source.getWidth();
    int height = source.getHeight();

    Paint paint = new Paint();
    paint.setAntiAlias(true);/*from  w  ww  .  j  av a 2 s.c om*/
    paint.setColor(Color.WHITE);

    Bitmap clipped = Bitmap.createBitmap(width, height, Config.ARGB_8888);
    Canvas canvas = new Canvas(clipped);
    canvas.drawRoundRect(new RectF(0, 0, width, height), radius, radius, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));

    Bitmap rounded = Bitmap.createBitmap(width, height, Config.ARGB_8888);
    canvas = new Canvas(rounded);
    canvas.drawBitmap(source, 0, 0, null);
    canvas.drawBitmap(clipped, 0, 0, paint);

    source.recycle();
    clipped.recycle();

    return rounded;
}

From source file:Main.java

public static Drawable resizeImage(Bitmap bitmap, int newWidth, int newHeight) {

    Bitmap BitmapOrg = bitmap;
    int width = BitmapOrg.getWidth();
    int height = BitmapOrg.getHeight();

    // calculate the scale
    float scaleWidth = ((float) newWidth) / width;
    float scaleHeight = ((float) newHeight) / height;

    // create a matrix for the manipulation
    Matrix matrix = new Matrix();
    // resize the Bitmap
    matrix.postScale(scaleWidth, scaleHeight);
    // if you want to rotate the Bitmap
    // matrix.postRotate(45);

    // recreate the new Bitmap
    Bitmap resizedBitmap = Bitmap.createBitmap(BitmapOrg, 0, 0, width, height, matrix, true);

    // make a Drawable from Bitmap to allow to set the Bitmap
    // to the ImageView, ImageButton or what ever
    return new BitmapDrawable(resizedBitmap);
}

From source file:Main.java

public static Bitmap getRoundedShape(Bitmap scaleBitmapImage, int width) {
    // TODO Auto-generated method stub
    int targetWidth = width;
    int targetHeight = width;
    Bitmap targetBitmap = Bitmap.createBitmap(targetWidth, targetHeight, Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(targetBitmap);
    Path path = new Path();
    path.addCircle(((float) targetWidth - 1) / 2, ((float) targetHeight - 1) / 2,
            (Math.min(((float) targetWidth), ((float) targetHeight)) / 2), Path.Direction.CCW);
    canvas.clipPath(path);/*from w  w w  .java2 s. c o m*/
    Bitmap sourceBitmap = scaleBitmapImage;
    canvas.drawBitmap(sourceBitmap, new Rect(0, 0, sourceBitmap.getWidth(), sourceBitmap.getHeight()),
            new Rect(0, 0, targetWidth, targetHeight), null);
    return targetBitmap;
}

From source file:Main.java

static public Bitmap cropBitmap(Bitmap src, int x, int y, int width, int height, boolean isRecycle) {
    if (x == 0 && y == 0 && width == src.getWidth() && height == src.getHeight()) {
        return src;
    }/* w w w.  j  a  v  a2 s  .  c  o m*/
    Bitmap dst = Bitmap.createBitmap(src, x, y, width, height);
    if (isRecycle && dst != src) {
        src.recycle();
    }
    return dst;
}

From source file:Main.java

public static Drawable scaleImage(Drawable paramDrawable, float paramFloat1, float paramFloat2) {
    BitmapDrawable localBitmapDrawable = null;
    if (paramDrawable != null) {
        Bitmap localBitmap = ((BitmapDrawable) paramDrawable).getBitmap();
        int i = localBitmap.getWidth();
        int j = localBitmap.getHeight();
        Matrix localMatrix = new Matrix();
        localMatrix.postScale(paramFloat1, paramFloat2);
        localBitmapDrawable = new BitmapDrawable(
                Bitmap.createBitmap(localBitmap, 0, 0, i, j, localMatrix, true));
    }/*from w ww.ja va 2 s.  c o  m*/
    return localBitmapDrawable;
}