Following method tells how to convert a drawable into bitmap
// method to convert a drawable into Bitmap
public static Bitmap drawableToBitmap (Drawable drawable) {
// check if drawable is the instance of BitmapDrawable
if (drawable instanceof BitmapDrawable) {
return ((BitmapDrawable)drawable).getBitmap();
}
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;
}
Hope this method helps you.
0 Comment(s)