Example usage for android.graphics.drawable Drawable draw

List of usage examples for android.graphics.drawable Drawable draw

Introduction

In this page you can find the example usage for android.graphics.drawable Drawable draw.

Prototype

public abstract void draw(@NonNull Canvas canvas);

Source Link

Document

Draw in its bounds (set via setBounds) respecting optional effects such as alpha (set via setAlpha) and color filter (set via setColorFilter).

Usage

From source file:Main.java

public static Bitmap view2Bitmap(View view) {
    if (view == null)
        return null;
    Bitmap ret = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(ret);
    Drawable bgDrawable = view.getBackground();
    if (bgDrawable != null) {
        bgDrawable.draw(canvas);
    } else {/*  w w w .  j a  v a2  s. c  o m*/
        canvas.drawColor(Color.WHITE);
    }
    view.draw(canvas);
    return ret;
}

From source file:Main.java

public static Bitmap getBitmapFromView(View view) {
    Bitmap returnedBitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(returnedBitmap);
    Drawable bgDrawable = view.getBackground();
    if (bgDrawable != null)
        bgDrawable.draw(canvas);
    else/*from  www.  ja v  a 2  s .com*/
        canvas.drawColor(Color.WHITE);
    view.draw(canvas);
    return returnedBitmap;
}

From source file:Main.java

private static Bitmap drawToBitmap(Resources resources, int drawableResourceID, Bitmap bitmap) {
    Drawable drawable = resources.getDrawable(drawableResourceID);
    drawable.setBounds(0, 0, bitmap.getWidth(), bitmap.getHeight());
    drawable.draw(new Canvas(bitmap));
    return bitmap;
}

From source file:org.michaelevans.etsyblur.utils.Utils.java

public static Bitmap drawViewToBitmap(View view, int color) {
    Bitmap returnedBitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(returnedBitmap);
    Drawable bgDrawable = view.getBackground();
    if (bgDrawable != null)
        bgDrawable.draw(canvas);
    else//from   w ww. j  a  v  a 2 s.co  m
        canvas.drawColor(color);
    view.draw(canvas);
    return returnedBitmap;
}

From source file:Main.java

public static Bitmap getBitmapFromView(View view) {
    //Define a bitmap with the same size as the view
    Bitmap returnedBitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
    //Bind a canvas to it
    Canvas canvas = new Canvas(returnedBitmap);
    //Get the view's background
    Drawable bgDrawable = view.getBackground();
    if (bgDrawable != null)
        //has background drawable, then draw it on the canvas
        bgDrawable.draw(canvas);
    else//from w ww . j  a  va  2  s.  c  o m
        //does not have background drawable, then draw white background on the canvas
        canvas.drawColor(Color.WHITE);
    // draw the view on the canvas
    view.draw(canvas);
    //return the bitmap
    return returnedBitmap;
}

From source file:Main.java

private static Bitmap toBitmap(Drawable drawable, int width, int height) {

    Bitmap bmp = Bitmap.createBitmap(width, height, Config.ARGB_8888);
    Canvas c = new Canvas(bmp);
    drawable.setBounds(new Rect(0, 0, width, height));
    drawable.draw(c);

    return bmp;/*from   w w w .  j  a v  a 2  s .c om*/
}

From source file:Main.java

public static Bitmap convertBitmap(Drawable drawable, int width, int height) {
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, width, height);
    drawable.draw(canvas);
    return bitmap;
}

From source file:com.achep.acdisplay.graphics.IconFactory.java

@NonNull
private static Bitmap createEmptyIcon(@NonNull Resources res, int size) {
    Paint paint = new Paint();
    paint.setAntiAlias(true);// www  .ja va2s . c  o  m
    paint.setColor(0xDDCCCCCC); // white gray

    final float radius = size / 2f;

    Bitmap icon = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_4444);
    Canvas canvas = new Canvas(icon);
    canvas.drawCircle(radius, radius, radius, paint);

    Drawable drawable = res.getDrawable(R.drawable.ic_action_warning_white);
    drawable.setBounds(0, 0, size, size);
    drawable.draw(canvas);

    return icon;
}

From source file:Main.java

public static Bitmap convertToBitmap(Drawable drawable, int width, int height) {
    Bitmap outputBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(outputBitmap);

    drawable.setBounds(0, 0, width, height);
    drawable.draw(canvas);

    return outputBitmap;
}

From source file:Main.java

public static Bitmap drawableToBitmap(Drawable drawable, int width, int height) {
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, width, height);
    drawable.draw(canvas);
    return bitmap;
}