List of utility methods to do Drawable to Bitmap Convert
Bitmap | DrawableToBitmap(Drawable drawable) Drawable To Bitmap try { Bitmap bitmap = Bitmap .createBitmap( drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565); Canvas canvas = new Canvas(bitmap); ... |
Bitmap | convertDrawableToBitmap(Drawable drawable) convert Drawable To Bitmap Bitmap bitmap = Bitmap
.createBitmap(
drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight(),
drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
: Bitmap.Config.RGB_565);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),
...
|
Bitmap | drawable2Bitmap(Drawable drawable) drawable Bitmap int width = drawable.getIntrinsicWidth(); int height = drawable.getIntrinsicHeight(); Bitmap bitmap = Bitmap .createBitmap( width, height, drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565); ... |
Bitmap | drawableToBitmap(Drawable drawable) drawable To Bitmap Bitmap bitmap = Bitmap
.createBitmap(
drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight(),
drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
: Bitmap.Config.RGB_565);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),
...
|
Bitmap | drawableToBitmap(Drawable drawable, int width, int height) drawable To Bitmap Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, (int) (height / 2.0), width, height); drawable.draw(canvas); return bitmap; |
Bitmap | getBitmap(Resources resources, int drawableResourceId) get Bitmap return BitmapFactory.decodeResource(resources, drawableResourceId);
|
BitmapDrawable | getBitmapDrawable(Context context, int resId) get Bitmap Drawable BitmapFactory.Options opt = new BitmapFactory.Options(); opt.inPreferredConfig = Bitmap.Config.RGB_565; opt.inPurgeable = true; opt.inInputShareable = true; InputStream is = context.getResources().openRawResource(resId); Bitmap bitmap = BitmapFactory.decodeStream(is, null, opt); try { is.close(); ... |
Bitmap | from(Drawable drawable) from BitmapDrawable bitDrawable = (BitmapDrawable) drawable;
return bitDrawable.getBitmap();
|
Bitmap | drawableToBitmap(Drawable drawable) drawable To Bitmap Bitmap bitmap = Bitmap
.createBitmap(
drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight(),
drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
: Bitmap.Config.RGB_565);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),
...
|
Bitmap | drawableToBitmap(Drawable drawable) drawable To Bitmap Bitmap bitmap = Bitmap
.createBitmap(
drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight(),
drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
: Bitmap.Config.RGB_565);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),
...
|