Android中图像的几何变化中Matrix的使用

来源:互联网 发布:淘宝群怎么添加到首页 编辑:程序博客网 时间:2024/04/28 09:49

Android中图像的几何变化可以方便地通过Matrix来实现,通过Matrix的几何变化达到图像的几何变化。

 

Android中通过Matrix matrix = new Matrix();后得来的matrix为一单位矩阵E:

matrix.toString() = Matrix{[1.0, 0.0, 0.0][0.0, 1.0, 0.0][0.0, 0.0, 1.0]}

我们也可以首先定义一个含有9个原始的数组,如:float f4[] = {  0.0F, -1.0F,  0.0F,  -1.0F,  0.0F,  0.0F,  0.0F,  0.0F,  1.0F};然后通过matrix.setValues(f4);对Matrix重新赋值。

 

设对给定的图像依次进行了基本变化F1F2F3…..Fn,它们的变化矩阵分别为T1T2T3…..Tn,图像复合变化的矩 阵T可以表示为:T= TnTn-1…T1

Android提供了很多的API函数来操作Matrix:

平移:public void setTranslate (float dx, float dy)

旋转:public void setRotate (float degrees)  //rotate about (0,0)

public void setRotate (float degrees, float px, float py)  //rotate about (px,py)