converting drawable resource image into bitmap converting drawable resource image into bitmap android android

converting drawable resource image into bitmap


You probably mean Notification.Builder.setLargeIcon(Bitmap), right? :)

Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.large_icon);notBuilder.setLargeIcon(largeIcon);

This is a great method of converting resource images into Android Bitmaps.


Drawable myDrawable = getResources().getDrawable(R.drawable.logo);Bitmap myLogo = ((BitmapDrawable) myDrawable).getBitmap();

Since API 22 getResources().getDrawable() is deprecated, so we can use following solution.

Drawable vectorDrawable = VectorDrawableCompat.create(getResources(), R.drawable.logo,  getContext().getTheme());Bitmap myLogo = ((BitmapDrawable) vectorDrawable).getBitmap();


Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.my_drawable);

Context can be your current Activity.