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

posted on   荷楠仁  阅读(4262)  评论(0编辑  收藏  举报

编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义

导航

统计

点击右上角即可分享
微信分享提示