List of utility methods to do Drawable to Bitmap Convert
Bitmap | drawableToBitmap(Drawable drawable) drawable To Bitmap BitmapDrawable bd = (BitmapDrawable) drawable;
Bitmap bitmap = bd.getBitmap();
return bitmap;
|
Bitmap | drawableToBitmap(Drawable drawable) drawable To Bitmap if (drawable == null) { return null; if (drawable instanceof BitmapDrawable) { return ((BitmapDrawable) drawable).getBitmap(); int width = drawable.getIntrinsicWidth(); width = width > 0 ? width : 1; ... |
Bitmap | drawableToBitmap(Drawable drawable) drawable To Bitmap if (drawable instanceof BitmapDrawable) { return ((BitmapDrawable) drawable).getBitmap(); Canvas canvas = new Canvas(); Bitmap bitmap = Bitmap.createBitmap(drawable.getMinimumWidth(), drawable.getMinimumHeight(), Config.ARGB_8888); canvas.setBitmap(bitmap); drawable.draw(canvas); ... |
Bitmap | drawableToBitmap(Drawable drawable) drawable To Bitmap if (drawable instanceof BitmapDrawable) { return ((BitmapDrawable) drawable).getBitmap(); final Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); drawable.draw(canvas); ... |
Bitmap | convertToBitmap(final Drawable drawable) convert To Bitmap return ((BitmapDrawable) drawable).getBitmap();
|
Bitmap | drawableToBitmap(Drawable drawable) drawable To Bitmap int w = drawable.getIntrinsicWidth(); int h = drawable.getIntrinsicHeight(); Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565; Bitmap bitmap = Bitmap.createBitmap(w, h, config); Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, w, h); drawable.draw(canvas); ... |
Bitmap | drawableToBitmap(Drawable drawable) drawable To Bitmap Bitmap bitmap = Bitmap
.createBitmap(
drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight(),
drawable.getOpacity() != PixelFormat.OPAQUE ? Config.ARGB_8888
: Config.RGB_565);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),
...
|
Bitmap | getMutableBitmap(Drawable drawable) get Mutable Bitmap if (drawable.getIntrinsicHeight() > 0 && drawable.getIntrinsicWidth() > 0) { Bitmap bitmap = Bitmap.createBitmap( drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.RGB_565); Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); drawable.draw(canvas); ... |