How to rotate a canvas at a specific point using android.graphics.Camera.rotateX(angle)

前端 未结 4 1050
一向
一向 2021-02-06 12:27

I am trying to use the Camera (android.graphics.Camera not the hardware camera) to rotate a views canvas around a specific point, in this instance the middle of the canvas.

4条回答
  •  花落未央
    2021-02-06 12:50

    Use this as the transformation in your animation class

    protected void applyTransformation(float interpolatedTime, Transformation t) {
    
        final float fromDegrees = 0;
    
        float degrees = fromDegrees
    
        + ((180- fromDegrees) * interpolatedTime);
    
        final float centerX = mCenterX;
    
        final float centerY = mCenterY;
    
        final Camera camera = mCamera;
    
        final Matrix matrix = t.getMatrix();
    
        camera.save();
    
        camera.rotateX(degrees);
    
        camera.getMatrix(matrix);
    
        camera.restore();
    
        matrix.preTranslate(-centerX, -centerY);
    
        matrix.postTranslate(centerX, centerY);
    
    }
    

提交回复
热议问题