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

public static Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth) {
    int width = bm.getWidth();
    int height = bm.getHeight();
    float scaleWidth = ((float) newWidth) / width;
    float scaleHeight = ((float) newHeight) / height;
    // CREATE A MATRIX FOR THE MANIPULATION
    Matrix matrix = new Matrix();
    // RESIZE THE BIT MAP
    matrix.postScale(scaleWidth, scaleHeight);

    // "RECREATE" THE NEW BITMAP
    Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);

    return resizedBitmap;
}

From source file:Main.java

public static Bitmap getRoundedCornerBitmap(Bitmap srcBitmap, float radius) {
    Bitmap resultBitmap = Bitmap.createBitmap(srcBitmap.getWidth(), srcBitmap.getHeight(),
            Bitmap.Config.ARGB_8888);/*  w ww .jav a2s. c om*/
    Canvas canvas = new Canvas(resultBitmap);
    Paint paint = new Paint();
    Rect rect = new Rect(0, 0, srcBitmap.getWidth(), srcBitmap.getHeight());
    RectF rectF = new RectF(rect);
    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(0xBDBDBE);
    canvas.drawRoundRect(rectF, radius, radius, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(srcBitmap, rect, rect, paint);
    return resultBitmap;
}

From source file:Main.java

public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, float roundPx) {
    return getRoundedCornerBitmap(bitmap, roundPx, bitmap.getWidth(), bitmap.getHeight());
}

From source file:Main.java

public static Bitmap punchAHoleInABitmap(Context context, Bitmap foreground, float x1, float y1) {
    Bitmap bitmap = Bitmap.createBitmap(foreground.getWidth(), foreground.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint();
    canvas.drawBitmap(foreground, 0, 0, paint);
    paint.setAntiAlias(true);/*  w  w w. j av  a 2  s.co m*/
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
    float radius = (float) (getScreenSize(context).x * .06);
    canvas.drawCircle(x1, y1 - 450, radius, paint);
    return bitmap;
}

From source file:Main.java

public static Bitmap resizeBitmap(Bitmap bitmap, int maxLength) {
    if (null == bitmap)
        return null;
    int w = bitmap.getWidth();
    int h = bitmap.getHeight();
    float scale = (float) maxLength / h;
    Matrix matrix = new Matrix();
    matrix.postScale(scale, scale);//  w w w .j  a  v  a  2  s  .com
    Bitmap zoomedBitmap = Bitmap.createBitmap(bitmap, 0, 0, w, h, matrix, true);
    return zoomedBitmap;
}

From source file:Main.java

public static int[] getImageSize(Context context, int drawableId) {
    Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), drawableId);
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    if (bitmap != null && bitmap.isRecycled()) {
        bitmap.recycle();//from  ww w.  j  av  a2s .c o m
    }
    int size[] = { width, height };
    return size;
}

From source file:Main.java

private static Bitmap rotateBitmap(Bitmap bitmap, int rotate) {
    if (bitmap == null)
        return null;

    int w = bitmap.getWidth();
    int h = bitmap.getHeight();

    // Setting post rotate to 90  
    Matrix mtx = new Matrix();
    mtx.postRotate(rotate);/*  w  w  w . j  a va  2 s . com*/
    return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true);
}

From source file:Main.java

/**
 * Returns semi-rounded bitmap. This is used for displaying atn promotion images.
 * // ww w .  j ava 2s.  co m
 * @param context
 * @param input
 * @return
 */
public static Bitmap getSemiRoundedBitmap(Context context, Bitmap input) {
    Bitmap output = Bitmap.createBitmap(input.getWidth(), input.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);
    final float densityMultiplier = context.getResources().getDisplayMetrics().density;
    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, input.getWidth(), input.getHeight());
    final RectF rectF = new RectF(rect);
    //make sure that our rounded corner is scaled appropriately
    final float roundPx = densityMultiplier * 10;
    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
    //draw rectangles over the corners we want to be square
    canvas.drawRect(input.getWidth() / 2, 0, input.getWidth(), input.getHeight() / 2, paint);
    canvas.drawRect(input.getWidth() / 2, input.getHeight() / 2, input.getWidth(), input.getHeight(), paint);
    paint.setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(input, 0, 0, paint);
    input.recycle();

    return output;
}

From source file:Main.java

public static Bitmap rotateBitmap(Bitmap bitmap, int rotate) {
    if (bitmap == null)
        return null;

    int w = bitmap.getWidth();
    int h = bitmap.getHeight();

    // Setting post rotate to 90
    Matrix mtx = new Matrix();
    mtx.postRotate(rotate);/*from ww  w  . jav a2  s  .c o m*/
    return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true);
}

From source file:Main.java

public static Bitmap boost(Bitmap src, int type, float percent) {
    int width = src.getWidth();
    int height = src.getHeight();
    Bitmap bmOut = Bitmap.createBitmap(width, height, src.getConfig());

    int A, R, G, B;
    int pixel;//from www  . j  a v a2s .  c  o m

    for (int x = 0; x < width; ++x) {
        for (int y = 0; y < height; ++y) {
            pixel = src.getPixel(x, y);
            A = Color.alpha(pixel);
            R = Color.red(pixel);
            G = Color.green(pixel);
            B = Color.blue(pixel);
            if (type == 1) {
                R = (int) (R * (1 + percent));
                if (R > 255)
                    R = 255;
            } else if (type == 2) {
                G = (int) (G * (1 + percent));
                if (G > 255)
                    G = 255;
            } else if (type == 3) {
                B = (int) (B * (1 + percent));
                if (B > 255)
                    B = 255;
            }
            bmOut.setPixel(x, y, Color.argb(A, R, G, B));
        }
    }
    return bmOut;
}