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

前端 未结 4 1042
一向
一向 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 13:06

    This worked for me:

    @Override
    public void drawPixmap3D(Pixmap pixmap, int x, int y, int r) {
        Camera camera = mCamera;
        int cx = pixmap.getWidth()/2;
        camera.save();
        camera.rotateY(r);
        camera.getMatrix(mtx);
        mtx.preTranslate(-cx, 0);
        mtx.postTranslate(x, y);
        camera.restore();
        canvas.drawBitmap(((AndroidPixmap)pixmap).bitmap, mtx, this.paint);
    }
    

提交回复
热议问题