Save canvas then restore, why is that?

后端 未结 5 949
太阳男子
太阳男子 2021-01-31 02:32

I often see the following code

canvas.save().
canvas translate or rotate
some drawing
canvas.restore

I don\'t understand why we save and then

5条回答
  •  无人及你
    2021-01-31 03:10

    Working with the canvas involves all manner of translate,scale,rotate,skew procedures on the canvas. The save() method preserves a state before any of the aforementioned augmentation in place, restore() rewinds to a state in time where no augmentation is injected. In other words, you can save a pre state before any transformation of the canvas, do your rotations and whatever else you want to during the process, but when your finished rewind to the state before any augmentation.

提交回复
热议问题