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 drawIn(Canvas canvas, Bitmap bitmap, Rect display, int x) {
    if (bitmap != null) {
        Rect source = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
        display = new Rect(display.left + x, display.top + x, display.right - x, display.bottom - x);
        canvas.drawBitmap(bitmap, source, display, null);
        return x + display.width();
    }//from  ww  w . j  a  v  a 2 s .c  om
    return 0;
}

From source file:Main.java

public static Bitmap blurBitmap(Context context, Bitmap bitmap, float radius) {
    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, bitmap);

    blurScript.setRadius(radius);/* www  .  j  a  v  a2s  .co  m*/

    blurScript.setInput(allIn);
    blurScript.forEach(allOut);

    allOut.copyTo(outBitmap);

    bitmap.recycle();
    rs.destroy();

    return outBitmap;
}

From source file:Main.java

public static Bitmap toRoundCorner(Bitmap bitmap, int pixels) {

    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    int color = 0xff424242;
    Paint paint = new Paint();
    Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    RectF rectF = new RectF(rect);
    float roundPx = pixels;

    paint.setAntiAlias(true);/*  w ww . jav  a  2s. co m*/
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    bitmap.recycle();
    return output;
}

From source file:Main.java

public static Bitmap getMatrixBitmap(Bitmap bm, int w, int h, boolean needRecycle) {
    int width = bm.getWidth();
    int height = bm.getHeight();
    boolean isCompress = (width > w && height > h) && (w != 0 && h != 0);
    if (isCompress) {
        float scaleWidth = ((float) w) / width;
        float scaleHeight = ((float) h) / height;
        float scale = Math.max(scaleWidth, scaleHeight);
        Matrix matrix = new Matrix();
        matrix.postScale(scale, scale);//from w  w  w.jav  a2  s .co  m
        Bitmap bitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, true);
        if (needRecycle && bm != null && bm != bitmap) {
            bm.recycle();
        }
        return bitmap;
    } else {
        return bm;
    }

}

From source file:Main.java

public static Bitmap getScreenFitBitmap(Bitmap src, int dispWidth, int dispHeight) {
    int srcWidth = src.getWidth();
    int srcHeight = src.getHeight();

    float scale = (float) dispWidth / srcWidth;

    Matrix matrix = new Matrix();
    matrix.postScale(scale, scale);/* w ww.  ja va  2 s .c  o m*/

    return Bitmap.createBitmap(src, 0, 0, srcWidth, srcHeight, matrix, true);
}

From source file:Main.java

/**
 * Gets the bitmap with rounded corners/* w  w  w.ja  v a2 s  .c  o  m*/
 *
 * @param bitmap Bitmap for processing
 * @param pixels Picture diameter in pixels
 * @return Rounded picture
 */
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int pixels) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);
    final float roundPx = pixels;

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);

    return output;
}

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);//from  w  ww . ja v a  2  s  .c om
    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 fillet(Bitmap bitmap, int pixels) {
    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(rect);
    final float roundPx = pixels;

    paint.setAntiAlias(true);/*from   ww w .ja  va  2s .  c o  m*/
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(Color.BLACK);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    return output;
}

From source file:Main.java

public static Bitmap clearBitmap(Bitmap sourceBitmap) {
    Bitmap newBitmap = Bitmap.createBitmap(sourceBitmap, 0, 0, sourceBitmap.getWidth(),
            sourceBitmap.getHeight());
    Bitmap mutableBitmap = newBitmap.copy(Bitmap.Config.ARGB_8888, true);
    mutableBitmap.eraseColor(Color.TRANSPARENT);
    return mutableBitmap;
}

From source file:Main.java

/**
 * Fills the bitmap's pixels of the specified Color to transparency.
 * /*from ww  w  .j  av a  2  s . com*/
 * @param aBitmap bitmap to process
 * @param aColor color to fill
 * @return bmp
 */
@SuppressLint("NewApi")
public static Bitmap eraseBG(Bitmap aBitmap, int aColor) {
    int width = aBitmap.getWidth();
    int height = aBitmap.getHeight();
    Bitmap b = aBitmap.copy(Config.ARGB_8888, true);
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB_MR1) {
        b.setHasAlpha(true);
    }

    int[] pixels = new int[width * height];
    aBitmap.getPixels(pixels, 0, width, 0, 0, width, height);

    for (int i = 0; i < width * height; i++) {
        if (pixels[i] == aColor) {
            pixels[i] = 0;
        }
    }

    b.setPixels(pixels, 0, width, 0, 0, width, height);

    return b;
}