core-ktx / androidx.graphics / android.graphics.Bitmap / applyCanvas

applyCanvas

inline fun Bitmap.applyCanvas(block: Canvas.() -> Unit): Bitmap

Creates a new Canvas to draw on this bitmap and executes the specified block on the newly created canvas. Example:

return Bitmap.createBitmap(…).applyCanvas {
   drawLine(…)
   translate(…)
   drawRect(…)
}