Example usage for android.graphics Canvas getHeight

List of usage examples for android.graphics Canvas getHeight

Introduction

In this page you can find the example usage for android.graphics Canvas getHeight.

Prototype

public int getHeight() 

Source Link

Document

Returns the height of the current drawing layer

Usage

From source file:Main.java

public static Bitmap getBitmap(Drawable drawable, boolean scaleBitmap, int width, int height) {
    Bitmap bitmap;//from   w ww. ja  v  a  2s  .co m
    if (drawable instanceof BitmapDrawable) {
        bitmap = ((BitmapDrawable) drawable).getBitmap();
    } else {
        bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
                Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        drawable.draw(canvas);
    }
    if (scaleBitmap) {
        bitmap = Bitmap.createScaledBitmap(bitmap, width, height, true);
    }
    return bitmap;
}

From source file:Main.java

public static Bitmap drawableToBitmap(Drawable drawable) {
    if (drawable instanceof BitmapDrawable) {
        return ((BitmapDrawable) drawable).getBitmap();
    }/*  w ww .  j a va 2s .  c o m*/

    int width = drawable.getIntrinsicWidth();
    width = width > 0 ? width : 1;
    int height = drawable.getIntrinsicHeight();
    height = height > 0 ? height : 1;

    Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);

    return bitmap;
}

From source file:Main.java

public static Bitmap getBitmapFromDrawable(Drawable drawable) {
    if (drawable instanceof BitmapDrawable) {
        return ((BitmapDrawable) drawable).getBitmap();
    }/* www  .jav  a  2s .c o  m*/

    int width = drawable.getIntrinsicWidth();
    width = width > 0 ? width : 1;
    int height = drawable.getIntrinsicHeight();
    height = height > 0 ? height : 1;

    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);

    return bitmap;
}

From source file:Main.java

public static Bitmap vectorToBitmap(Context context, Drawable vector) {
    final Bitmap bitmap = Bitmap.createBitmap(vector.getIntrinsicWidth(), vector.getIntrinsicHeight(),
            Bitmap.Config.ARGB_8888);// w  w w. ja  v  a2s.c  om
    final Canvas canvas = new Canvas(bitmap);
    vector.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    vector.draw(canvas);
    return bitmap;
}

From source file:Main.java

public static Bitmap drawableToBitmap(Drawable drawable) {

    if (drawable instanceof BitmapDrawable) {
        return ((BitmapDrawable) drawable).getBitmap();
    }/*  ww  w .ja v a 2s  .c o m*/

    Bitmap bitmap = Bitmap.createBitmap(128, 128, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);

    return bitmap;
}

From source file:Main.java

public static Bitmap drawableToBitmap(Drawable drawable) {
    if (drawable instanceof BitmapDrawable) {
        return ((BitmapDrawable) drawable).getBitmap();
    }//from  w w  w  . j av a2  s. c  o m

    // We ask for the bounds if they have been set as they would be most
    // correct, then we check we are  > 0
    final int width = !drawable.getBounds().isEmpty() ? drawable.getBounds().width()
            : drawable.getIntrinsicWidth();

    final int height = !drawable.getBounds().isEmpty() ? drawable.getBounds().height()
            : drawable.getIntrinsicHeight();

    // Now we check we are > 0
    final Bitmap bitmap = Bitmap.createBitmap(width <= 0 ? 1 : width, height <= 0 ? 1 : height,
            Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);

    return bitmap;
}

From source file:Main.java

/**
 * Use touch-icon or higher-resolution favicon and round the corners.
 * @param context    Context used to get resources.
 * @param touchIcon  Touch icon bitmap.// w  ww  . jav  a2  s. c om
 * @param canvas     Canvas that holds the touch icon.
 */
private static void drawTouchIconToCanvas(Context context, Bitmap touchIcon, Canvas canvas) {
    Rect iconBounds = new Rect(0, 0, canvas.getWidth(), canvas.getHeight());
    Rect src = new Rect(0, 0, touchIcon.getWidth(), touchIcon.getHeight());
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setFilterBitmap(true);
    canvas.drawBitmap(touchIcon, src, iconBounds, paint);
    // Convert dp to px.
    int borderRadii = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, TOUCHICON_BORDER_RADII,
            context.getResources().getDisplayMetrics());
    Path path = new Path();
    path.setFillType(Path.FillType.INVERSE_WINDING);
    RectF rect = new RectF(iconBounds);
    rect.inset(INSET_DIMENSION_FOR_TOUCHICON, INSET_DIMENSION_FOR_TOUCHICON);
    path.addRoundRect(rect, borderRadii, borderRadii, Path.Direction.CW);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
    canvas.drawPath(path, paint);
}

From source file:Main.java

public static void drawShade(Canvas canvas, RectF bounds) {
    int w = canvas.getWidth();
    int h = canvas.getHeight();
    Paint p = new Paint();
    p.setStyle(Paint.Style.FILL);
    p.setColor(Color.BLACK & 0x88000000);

    RectF r = new RectF();
    r.set(0, 0, w, bounds.top);/*from   w  ww.j  ava  2  s  .  co  m*/
    canvas.drawRect(r, p);
    r.set(0, bounds.top, bounds.left, h);
    canvas.drawRect(r, p);
    r.set(bounds.left, bounds.bottom, w, h);
    canvas.drawRect(r, p);
    r.set(bounds.right, bounds.top, w, bounds.bottom);
    canvas.drawRect(r, p);
}

From source file:com.google.android.apps.santatracker.presentquest.util.VectorUtil.java

public static BitmapDescriptor vectorToBitmap(Context context, @DrawableRes int id) {
    Drawable vectorDrawable = ResourcesCompat.getDrawable(context.getResources(), id, null);
    Bitmap bitmap = Bitmap.createBitmap(vectorDrawable.getIntrinsicWidth(), vectorDrawable.getIntrinsicHeight(),
            Bitmap.Config.ARGB_8888);//from w w w  . j ava2s.c om
    Canvas canvas = new Canvas(bitmap);
    vectorDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    vectorDrawable.draw(canvas);
    return BitmapDescriptorFactory.fromBitmap(bitmap);
}

From source file:Main.java

public static Bitmap drawableToBitmap(Drawable drawable) {
    if (drawable instanceof BitmapDrawable) {
        return ((BitmapDrawable) drawable).getBitmap();
    }/* w w  w  .  ja v a2s.  co  m*/

    int width = drawable.getIntrinsicWidth();
    width = width > 0 ? width : 1;
    int height = drawable.getIntrinsicHeight();
    height = height > 0 ? height : 1;

    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);

    return bitmap;
}