Example usage for android.graphics Bitmap getWidth

List of usage examples for android.graphics Bitmap getWidth

Introduction

In this page you can find the example usage for android.graphics Bitmap getWidth.

Prototype

public final int getWidth() 

Source Link

Document

Returns the bitmap's width

Usage

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  .  j a  va  2 s.c o  m
    return blurBitmap(b, DEFAULT_BLUR_RADIUS, context);
}

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);/* ww  w  .j  ava 2  s . c om*/
    blurScript.setInput(allIn);
    blurScript.forEach(allOut);
    allOut.copyTo(outBitmap);
    bitmap.recycle();
    rs.destroy();
    return outBitmap;
}

From source file:Main.java

public static Bitmap scaleBitmap(Bitmap srcBmp, int iWidth, int iHeight) {
    float fWidth = srcBmp.getWidth();
    float fHeight = srcBmp.getHeight();

    if (fWidth > iWidth) {
        float mWidth = (float) (fWidth / 100);
        float fScale = (float) (iWidth / mWidth);
        fWidth *= (fScale / 100);//from  ww w  .  java 2 s .c o  m
        fHeight *= (fScale / 100);
    } else if (fHeight > iHeight) {
        float mHeight = (float) (fHeight / 100);
        float fScale = (float) (iHeight / mHeight);
        fWidth *= (fScale / 100);
        fHeight *= (fScale / 100);
    }
    return Bitmap.createScaledBitmap(srcBmp, (int) fWidth, (int) fHeight, true);
}

From source file:Main.java

public static Bitmap rotateBitmapDegree(Bitmap bm, int degree) {
    Bitmap returnBm;/* w ww . jav  a2s  .com*/
    int w = bm.getWidth();
    int h = bm.getHeight();

    Matrix matrix = new Matrix();
    matrix.postRotate(degree);

    returnBm = Bitmap.createBitmap(bm, 0, 0, w, h, matrix, true);

    if (bm != returnBm) {
        bm.recycle();
    }

    return returnBm;
}

From source file:Main.java

public static Bitmap circleBitmap(final Bitmap source) {
    int width = source.getWidth();
    int height = source.getHeight();

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

    Bitmap clipped = Bitmap.createBitmap(width, height, Config.ARGB_8888);
    Canvas canvas = new Canvas(clipped);
    final float radius = width > height ? height / 2 : width / 2;
    canvas.drawCircle(width / 2, height / 2, 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 Bitmap addWhiteBorder(Bitmap bmp, int borderSize) {
    Bitmap bmpWithBorder = Bitmap.createBitmap(bmp.getWidth() + borderSize * 2,
            bmp.getHeight() + borderSize * 2, bmp.getConfig());
    Canvas canvas = new Canvas(bmpWithBorder);
    canvas.drawColor(Color.WHITE);
    canvas.drawBitmap(bmp, borderSize, borderSize, null);
    return bmpWithBorder;
}

From source file:Main.java

public static Bitmap scaleToFitWidth(Bitmap b, int width) {
    if (b == null)
        return null;
    if (b.getWidth() <= width)
        return b;

    float factor = width / (float) b.getWidth();
    return Bitmap.createScaledBitmap(b, width, (int) (b.getHeight() * factor), true);
}

From source file:Main.java

public static Bitmap compressFixBitmap(Bitmap bitMap, int outWidth, int outHeight) {
    int width = bitMap.getWidth();
    int height = bitMap.getHeight();
    float scaleWidth = ((float) outWidth) / width;
    float scaleHeight = ((float) outHeight) / height;
    Matrix matrix = new Matrix();
    matrix.postScale(scaleWidth, scaleHeight);
    return Bitmap.createBitmap(bitMap, 0, 0, width, height, matrix, true);
}

From source file:Main.java

public static Bitmap scaleImg(Bitmap bm, int newWidth, int newHeight) {

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

    int newWidth1 = newWidth;
    int newHeight1 = newHeight;

    float scaleWidth = ((float) newWidth1) / width;
    float scaleHeight = ((float) newHeight1) / height;

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

    Bitmap newbm = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, true);
    return newbm;

}