Flutter CustomPainter canvas rotate pivot

允我心安 提交于 2019-12-11 17:28:02

问题


In my Android Studio project, I rotate the canvas simply as following

canvas.rotate(angle, cx, cy);

with cx and cy the center of the screen (i.e. the pivot). But in Flutter, there's only a single rotate method:

canvas.rotate(double radians)

and as you can see, when I tested the pivot it uses by drawing some rectangles and rotating it

and it uses top-left as pivot point. Is there a way to instruct Flutter to use my own provided pivot point?


回答1:


canvas.translate(cx, cy);
canvas.rotate(angle);
canvas.translate(-cx, -cy);

it's possible I have lines 1 and 3 reversed. Fixed.



来源:https://stackoverflow.com/questions/58042432/flutter-custompainter-canvas-rotate-pivot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!