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 getResizedBitmap(Bitmap image, int maxSize) {
    if (image == null)
        return null;

    int width = image.getWidth();
    int height = image.getHeight();

    float bitmapRatio = (float) width / (float) height;

    width = maxSize;/*from w  w  w  .ja v  a2  s . com*/
    height = (int) (width / bitmapRatio);

    return Bitmap.createScaledBitmap(image, width, height, true);
}

From source file:Main.java

public static Bitmap createRoundedBitmap(Context context, Bitmap bitmap, int radiusDP) {
    Bitmap bmp;/* w  ww . j av a  2 s  . c  om*/

    bmp = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    BitmapShader shader = new BitmapShader(bitmap, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);

    float radius = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, radiusDP,
            context.getResources().getDisplayMetrics());
    Canvas canvas = new Canvas(bmp);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setShader(shader);

    RectF rect = new RectF(0, 0, bitmap.getWidth(), bitmap.getHeight());
    canvas.drawRoundRect(rect, radius, radius, paint);

    return bmp;
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static Bitmap blur(Context context, Bitmap image) {
    int width = Math.round(image.getWidth() * BITMAP_SCALE);
    int height = Math.round(image.getHeight() * BITMAP_SCALE);

    Bitmap inputBitmap = Bitmap.createScaledBitmap(image, width, height, false);
    Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap);

    RenderScript rs = RenderScript.create(context);
    ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
    Allocation tmpIn = Allocation.createFromBitmap(rs, inputBitmap);
    Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap);
    theIntrinsic.setRadius(BLUR_RADIUS);
    theIntrinsic.setInput(tmpIn);//  www.  j  a  va  2s  .  c  o m
    theIntrinsic.forEach(tmpOut);
    tmpOut.copyTo(outputBitmap);

    return outputBitmap;
}

From source file:Main.java

public static Bitmap resizeDownToPixels(Bitmap bitmap, int targetPixels, boolean recycle) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    float scale = (float) Math.sqrt((double) targetPixels / (width * height));
    if (scale >= 1.0f)
        return bitmap;
    return resizeBitmapByScale(bitmap, scale, recycle);
}

From source file:Main.java

public static Bitmap resizeBitmap(Bitmap src, int max) {
    if (src == null)
        return null;

    int width = src.getWidth();
    int height = src.getHeight();
    float rate = 0.0f;

    if (width > height) {
        rate = max / (float) width;
        height = (int) (height * rate);
        width = max;/* w  ww. ja  v  a2  s.c o m*/
    } else {
        rate = max / (float) height;
        width = (int) (width * rate);
        height = max;
    }

    return Bitmap.createScaledBitmap(src, width, height, true);
}

From source file:Main.java

public static Bitmap rotaingBitmap(float degree, Bitmap bitmap) {
    Matrix matrix = new Matrix();
    matrix.postRotate(degree);/*from   www .  j  a  va 2 s  .c o m*/
    return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
}

From source file:Main.java

private static void drawTouchIconToCanvas(Bitmap touchIcon, Canvas canvas, Rect iconBounds) {
    Rect src = new Rect(0, 0, touchIcon.getWidth(), touchIcon.getHeight());

    // Paint used for scaling the bitmap and drawing the rounded rect.
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setFilterBitmap(true);/*from   ww w  .  j av  a  2  s  .c om*/
    canvas.drawBitmap(touchIcon, src, iconBounds, paint);

    // Construct a path from a round rect. This will allow drawing with
    // an inverse fill so we can punch a hole using the round rect.
    Path path = new Path();
    path.setFillType(Path.FillType.INVERSE_WINDING);
    RectF rect = new RectF(iconBounds);
    rect.inset(1, 1);
    path.addRoundRect(rect, 8f, 8f, Path.Direction.CW);

    // Reuse the paint and clear the outside of the rectangle.
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
    canvas.drawPath(path, paint);
}

From source file:Main.java

public static Bitmap doScale(Bitmap b, float scale) {
    Matrix matrix = new Matrix();
    matrix.postScale(scale, scale);//from  ww w.j  a v  a 2s .c o  m
    b = Bitmap.createBitmap(b, 0, 0, b.getWidth(), b.getHeight(), matrix, true);
    return b;
}

From source file:Main.java

public static void drawToCenterOfCanvas(Canvas canvas, Bitmap bp, int max_width, int max_height,
        Rect cacheRect) {/*ww  w  .  j  av a2  s .co  m*/
    final int b_w = bp.getWidth();
    final int b_h = bp.getHeight();
    if (b_w <= max_width && b_h <= max_height) { // center aligned
        canvas.drawBitmap(bp, (max_width - b_w) / 2, (max_height - b_h) / 2, null);
    } else { // scaled fix given rect size
        final float s_w = 1.0f * max_width / b_w;
        final float s_h = 1.0f * max_height / b_h;
        final float f_s = Math.min(s_w, s_h);
        final int f_w = (int) (b_w * f_s);
        final int f_h = (int) (b_h * f_s);
        cacheRect.set(0, 0, f_w, f_h);
        cacheRect.offset((max_width - f_w) / 2, (max_height - f_h) / 2);
        canvas.drawBitmap(bp, null, cacheRect, null);
    }
}

From source file:Main.java

public static Bitmap rotateBitmap(Bitmap bitmap) {

    Matrix matrix = new Matrix();
    matrix.postRotate(90f);/*from  ww  w .  j a v  a 2  s .c om*/

    return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
}