android画布缩放 移动demo,Android Canvas缩放(Scale)

Canvas缩放有以下两个方法:

public void scale (float sx, float sy) ;//以(0,0)为中心点,将画布长宽分别变为原来的sx/sy倍

public final void scale (float sx, float sy, float px, float py); //以(px,py)为中心点,将画布长宽分别变为原来的sx/sy倍

分析一下第二个方法的实现

/**

* Preconcat the current matrix with the specified scale.

*

* @param sx The amount to scale in X

* @param sy The amount to scale in Y

* @param px The x-coord for the pivot point (unchanged by the scale)

* @param py The y-coord for the pivot point (unchanged by the scale)

*/

public final void scale(float sx, float sy, float px, float py) {

translate(px, py);

scale(sx, sy);

translate(-px, -py);

}

其中translate(-px, -py);貌似和translate(px, py);抵消了,这样和直接调用scale(sx, sy);为何效果不一样呢?

是因为:第一步translate(px, py)移动的物理距离是px和py,经过scale(sx, sy)缩放后再通过translate(-px, -py)位移,移动的物理距离实际是-pxsx和-pysy,并未抵消。

具体参考:

https://www.it610.com/article/1294311483022319616.htm

https://blog.csdn.net/zhjin8510/article/details/100533755

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值