Canvas save restore存了什么,恢复了什么

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之前的状态。


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值