Flip vertically an Android Canvas
Asked Answered
J

2

11

Is there an easy way to flip a canvas in Android? I cant seem to find anything that allows me to flip it vertically so that zero on the y-axis is the bottom of the phone screen instead of the top. It's OK if the solution isn't especially fast because I'm not doing anything computationally intense with the canvas.

Thanks in advance.

Joachim answered 7/3, 2012 at 22:18 Comment(0)
B
30

Try

canvas.scale(1f, -1f, width / 2f, height / 2f)

See Canvas.scale documentation. The first two parameters are the amount to scale by.

Bb answered 7/3, 2012 at 22:21 Comment(0)
A
0

If you are drawing a bitmap, you can also use the Shader.TileMode of MIRROR, e.g.

val shader = BitmapShader(bitmap, Shader.TileMode.MIRROR, Shader.TileMode.MIRROR)
paint.shader = shader
canvas.drawRoundRect(roundRect, 20F, 20F, mPaint)
paint.shader = null
Audrey answered 30/9, 2019 at 8:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.