save and restore canvas around drawing the background

This commit is contained in:
tibbi 2019-01-12 17:55:38 +01:00
parent bab1211339
commit f9f247ecaf
1 changed files with 3 additions and 0 deletions

View File

@ -11,12 +11,15 @@ class EditorDrawCanvas(context: Context, attrs: AttributeSet) : View(context, at
override fun onDraw(canvas: Canvas) { override fun onDraw(canvas: Canvas) {
super.onDraw(canvas) super.onDraw(canvas)
canvas.save()
if (backgroundBitmap != null) { if (backgroundBitmap != null) {
val left = (width - backgroundBitmap!!.width) / 2 val left = (width - backgroundBitmap!!.width) / 2
val top = (height - backgroundBitmap!!.height) / 2 val top = (height - backgroundBitmap!!.height) / 2
canvas.drawBitmap(backgroundBitmap, left.toFloat(), top.toFloat(), null) canvas.drawBitmap(backgroundBitmap, left.toFloat(), top.toFloat(), null)
} }
canvas.restore()
} }
fun updateBackgroundBitmap(bitmap: Bitmap) { fun updateBackgroundBitmap(bitmap: Bitmap) {