Android: Matrix -> what is the different between preconcat and postconcat?

后端 未结 2 560
醉酒成梦
醉酒成梦 2020-12-07 10:21

I\'m using Matrix to scale and rotate Bitmaps. Now I\'m wondering what the difference between preconcat & postconcat is, or more precisely the difference between:

<
2条回答
  •  攒了一身酷
    2020-12-07 10:39

    I answered the question yesterday, but I feel sometiong wrong today ,So I correct the answer here:

    matrix:  float[] values ={1.2f,0.5f,30,0.5f,1.2f,30,0,0,1};
    
    //as we all know, the basic value in matrix,means no transformation added
    matrix2:  float[] values2 ={1f,0,0,0,1f,0,0,0,1};
    
    Let's say our matrix values are the values above.
    

    1、 when we do the transformation like below:

    matrix.preTranslate(-50, -50);
    
    is equals to do sequence transformation to matrix2 above like below:
    
    matrix2.postTranslate(-50, -50);
    matrix2.postSkew(0.5f/1.2f,0.5f/1.2f);// note here
    matrix2.postScale(1.2f, 1.2f);
    matrix2.postTranslate(30, 30);
    

    2、 when we do the transformation like below :

    matrix.preRotate(50);
    
    is equals to do sequence transformation to matrix2 like below:
    
    matrix2.postRotate(50);
    matrix2.postSkew(0.5f/1.2f,0.5f/1.2f);
    matrix2.postScale(1.2f, 1.2f);
    matrix2.postTranslate(30, 30);
    

    3、 when we do the transformation like below :

    matrix.preScale(1.3f,1.3f);
    
    is equals to do sequence transformation to matrix2 like below:
    
    matrix2.postScale(1.3f,1.3f);
    matrix2.postSkew(0.5f/1.2f,0.5f/1.2f);
    matrix2.postScale(1.2f, 1.2f);
    matrix2.postTranslate(30, 30);
    

    4、 when we do the transformation like below :

     matrix.preSkew(0.4f,0.4f);
    

    is equals to do sequence transformation to matrix2 like below:

     matrix2.postSkew(0.4f,0.4f);
     matrix2.postSkew(0.5f/1.2f,0.5f/1.2f);
     matrix2.postScale(1.2f, 1.2f);
     matrix2.postTranslate(30, 30);
    

提交回复
热议问题