android学习19--Matrix.mapPoints作用
2016-06-30 08:12
405 查看
android图形的旋转,缩放,平移都是用matrix实现的.可以用mapPoints来计算一个点旋转,缩放,平移后的坐标.看下面例子.
matrix表示沿x轴移动100个像素,沿y轴移动100个像素.points1的初始值是(0,0).matrix.mapPoints(points1)的作用就是把(0,0)沿x轴移动100个像素,沿y轴移动100个像素,结果为(100,100).
加一个典型的应用场景.假定现在有一个矩阵,想把这个矩形以某个点为缩放中心缩放.这时候就可以用mapPoints.看下面的代码.
源代码地址:
https://github.com/zhouyang209117/AndroidTutorial/tree/master/Game/ch4/Mappoints
Matrix matrix = new Matrix(); matrix.setTranslate(100f, 100f); float[] points1 = new float[]{0, 0}; matrix.mapPoints(points1);
matrix表示沿x轴移动100个像素,沿y轴移动100个像素.points1的初始值是(0,0).matrix.mapPoints(points1)的作用就是把(0,0)沿x轴移动100个像素,沿y轴移动100个像素,结果为(100,100).
加一个典型的应用场景.假定现在有一个矩阵,想把这个矩形以某个点为缩放中心缩放.这时候就可以用mapPoints.看下面的代码.
RectF rectf = new RectF(0, 0, 100, 200); float[] points = new float[]{rectf.left, rectf.top, rectf.right, rectf.bottom}; Matrix matrix = new Matrix(); matrix.setScale(2, 3, 0, 0); matrix.mapPoints(points); RectF scaledRectf = new RectF(points[0], points[1], points[2], points[3]);
源代码地址:
https://github.com/zhouyang209117/AndroidTutorial/tree/master/Game/ch4/Mappoints
相关文章推荐
- android 动画(4)自定义动画
- android编译
- Android中的责任链模式分析
- Android存储系统如何优化?
- android:layout_gravity和android:gravity
- iOS 使用WKWebView替换UIWebView(二)——代码实战(包括OC与JS互调)
- Swift 范的 CGRect、CGSize 和 CGPoint
- web中filter需要注入bean(如service,dao等bean)--- DelegatingFilterProxy
- ioS之Socket心跳包机制与实现
- iOS之实现后台socket长连接
- android 动画(3)属性动画
- android高级工程师应该会的知识
- iOS发展史(里程碑)
- Swift3.0带来的变化汇总系列三——函数和闭包写法上的微调
- 基于Android系统Api封装常用工具类
- 移动端适配问题
- android 动画(2)帧动画
- App后台学习
- 一个小白从零基础自学Android编程笔记之如何切换另一个活动(窗口)
- Android Error : No resource found that matches the given name 'Theme.AppCompat.Light'.