I need to convert solid color Drawable
to Bitmap
, because I need to use Bitmap
in library. How to do that?
This is my ColorDrawable
:
val blackColorDrawable = ColorDrawable(ContextCompat.getColor(this, R.color.colorPrimaryDark))
I need to convert solid color Drawable
to Bitmap
, because I need to use Bitmap
in library. How to do that?
This is my ColorDrawable
:
val blackColorDrawable = ColorDrawable(ContextCompat.getColor(this, R.color.colorPrimaryDark))
This is how I convert colorDrawable
to bitmap
try {
val bitmap = Bitmap.createBitmap(2, 2, Bitmap.Config.ARGB_8888)
val canvas = Canvas(bitmap)
blackColorDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight())
blackColorDrawable.draw(canvas)
return bitmap
} catch (e: Exception) {
e.printStackTrace()
return null
}