Flip Android Canvas Vertically

Is there an easy way to flip the canvas in Android? It seems I can’t find anything that allows me to flip it vertically, so zero on the y axis will be the bottom of the phone screen, not the top. This is normal if the solution is not particularly fast, because I am not doing anything intensive using the canvas.

Thanks in advance.

+9
source share
2 answers

Try

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

See the Canvas.scale documentation. The first two parameters are the scale to be scaled.

+22
source

If you are drawing a bitmap, you can also use Shader.TileMode from MIRROR , for example

 val shader = BitmapShader(bitmap, Shader.TileMode.MIRROR, Shader.TileMode.MIRROR) paint.shader = shader canvas.drawRoundRect(roundRect, 20F, 20F, mPaint) paint.shader = null 
0
source

Source: https://habr.com/ru/post/910210/


All Articles