我需要将纯色Drawable
转换为Bitmap
,因为我需要在库中使用Bitmap
。怎么做?
这是我的ColorDrawable
:
val blackColorDrawable = ColorDrawable(ContextCompat.getColor(this, R.color.colorPrimaryDark))
答案 0 :(得分:1)
这就是我将colorDrawable
转换为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
}