Android Drawable to Bitmap Conversion

 Android  Drawable to Bitmap Conversion 

1. Kotlin

val drawable = ContextCompat.getDrawable(this, R.drawable.icon)
val bitmap = drawable?.toBitmap()


2. JAVA

Drawable drawable = ContextCompat.getDrawable(getApplicationContext(), R.drawable.icon);
Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();

OR 
Bitmap bitmap1 = BitmapFactory.decodeResource(getResources(), R.drawable.icon);

No comments:

Post a Comment