Example usage for android.graphics Canvas getWidth

List of usage examples for android.graphics Canvas getWidth

Introduction

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

Prototype

public int getWidth() 

Source Link

Document

Returns the width of the current drawing layer

Usage

From source file:Main.java

public static float getRadius(Canvas canvas) {
    float width = canvas.getWidth();
    float height = canvas.getHeight();
    float minSize = width > height ? height : width;
    float radius = minSize / 2;
    return radius;
}

From source file:Main.java

/**
 * Draw the favicon with dominant color.
 * @param context Context used to create the intent.
 * @param favicon favicon bitmap./*from   w ww  . j av a 2 s.  com*/
 * @param canvas Canvas that holds the favicon.
 */
private static void drawFaviconToCanvas(Context context, Bitmap favicon, Canvas canvas) {
    Rect iconBounds = new Rect(0, 0, canvas.getWidth(), canvas.getHeight());
    int faviconSize = iconBounds.width() / 3;
    Bitmap scaledFavicon = Bitmap.createScaledBitmap(favicon, faviconSize, faviconSize, true);
    canvas.drawBitmap(scaledFavicon, iconBounds.exactCenterX() - scaledFavicon.getWidth() / 2.0f,
            iconBounds.exactCenterY() - scaledFavicon.getHeight() / 2.0f, null);
}

From source file:Main.java

public static Bitmap createBitmapFrom(Drawable drawable) {
    Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
            Bitmap.Config.ARGB_8888);//from   w w  w  .ja va2  s .  c  om
    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 getDrawableBitmap(Drawable drawable) {
    Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
            Bitmap.Config.ARGB_8888);//from www  .java  2s  .c o m
    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();
    }// www  . j  a v a 2  s. c  om

    Bitmap 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);

    return bitmap;
}

From source file:Main.java

public static Bitmap convertDrawableToBitmap(Drawable drawable) {
    if (drawable instanceof BitmapDrawable) {
        return ((BitmapDrawable) drawable).getBitmap();
    }/*from  w w w.jav  a2 s .  com*/

    Bitmap 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);

    return bitmap;
}

From source file:Main.java

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

    Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
            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 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 a v a  2s  .  c  o 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:Main.java

public static Bitmap drawableToBitmap(Drawable drawable) {
    if (drawable instanceof BitmapDrawable) {
        return ((BitmapDrawable) drawable).getBitmap();
    }// ww w.  j  a va  2 s.  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 drawableToBitmap(Drawable drawable) {
    if (drawable instanceof BitmapDrawable) {
        return ((BitmapDrawable) drawable).getBitmap();
    }/*w w  w  . j ava2s .c  o m*/

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

    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;
}