Issue
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))
Solution
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
}
Answered By - Bach Vu
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.