Hey guys 👋, I am trying to save a canvas as bitmap in my external drive. Is it at all possible in Compose to use something like:
Copy code
val b:Bitmap = canvas.drawToBitmap(Bitmap.Config.ARGB_8888)
Or is there an alternative to save a canvas?
n
Nader Jawad
03/30/2021, 4:10 AM
You can create your own ImageBitmap and create a DrawScope to issue drawing commands into it with the following:
fun drawScopeWithImageBitmap(width: Int, height: Int) {
val imageBitmap = ImageBitmap(width, height)
val imageBitmapCanvas = Canvas(imageBitmap)
CanvasDrawScope().draw(imageBitmapCanvas, Size(width, height) { // DrawScope
drawRect(Color.Red)
}
}