Android 为什么我们使用 canvas.save 或 canvas.restore?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3051981/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why do we use canvas.save or canvas.restore?
提问by Prabhat
I know what it does. If I dont use sometimes I can see the difference in alignments, sometimes I don't. My question is: if canvas.restore
restores the state previous to when it was saved, why aren't the changes made after save and before restore undone? The changes remain. Why?
我知道它的作用。如果我有时不使用,我可以看到对齐方式的差异,有时则看不到。我的问题是:如果canvas.restore
恢复保存之前的状态,为什么在保存之后和恢复之前所做的更改没有被撤消?变化依然存在。为什么?
回答by Ben L.
canvas.save
and canvas.restore
undo things like rotation and translation. They don't undo drawing on the canvas. The android canvas works similarly to the HTML5 canvas, so you can look at https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Canvas_tutorial/Transformationsif you need more clarification.
canvas.save
并canvas.restore
撤消诸如旋转和平移之类的操作。他们不会撤消画布上的绘图。android 画布的工作原理与 HTML5 画布类似,因此如果您需要更多说明,可以查看https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Canvas_tutorial/Transformations。