Here you can find the source of drawableToBitmap(Drawable drawable, int width, int height)
public static Bitmap drawableToBitmap(Drawable drawable, int width, int height)
//package com.java2s; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.drawable.Drawable; public class Main { 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); // canvas.setBitmap(bitmap); drawable.setBounds(0, (int) (height / 2.0), width, height); drawable.draw(canvas);/*from www .j a v a 2 s . co m*/ return bitmap; } }