Lee出品,转载注明出处 http://blog.csdn.net/hnulwt/article/details/40650473
时间紧急可以直接看黑体字部分,如有错误,请指出,谢谢。
源码:
/**
* Saves the current matrix and clip onto a private stack. Subsequent
* calls to translate,scale,rotate,skew,concat or clipRect,clipPath
* will all operate as usual, but when the balancing call to restore()
* is made, those calls will be forgotten, and the settings that existed
* before the save() will be reinstated.
*
* @return The value to pass to restoreToCount() to balance this save()
*/
public native int save();
native方法,从代码看不出什么了。看看注释:
保存当前的 Matrix 和 clip 在一个私有栈里, 随后调用translate , scale ,rotate ,skew ,concat 或者clipRect,clipPath均能正常操作。当调用与之对应的restore方法后,这些调用会被遗忘,在调用save方法之前的设置会被恢复。
查了其他资料,android有关资料太少了。找到HTML5的,和android的相似,看看canvas的绘制状态都包含什么东西:(注:有的可能是android没有的)
1,当前的transformatrion matrix
2,当前的裁剪区域 clip region.
3,这些属性:
strokeStyle, fillStyle, globalAlpha, lineWidth, lineCap, lineJoin, miterLimit, shadowOffsetX, shadowOffsetY, shadowBlur, shadowColor, globalCompositeOperation, font, textAlign, textBaseline.
canvas save restore 实际上一个入栈 和 出栈。调用restore的次数要 <= 调用save的次数。canvas也就是我们理解的画板,是一个状态机。他可以存储对canvas的平移translate、放缩scale、旋转rotate、错切skew、裁剪clip等操作。restore之后恢复到上次调用save之前的状态。