android学习19--Matrix.mapPoints作用
android图形的旋转,缩放,平移都是用matrix实现的.可以用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