5

我发现很少有关于如何操作路径对象的文档,特别是旋转。

我有一个绘画应用程序,我试图在其中加入“撤消”功能。每次用户的手指触摸视图直到他们的手指被抬起 - 他们的手指路径被保存为 ArrayList 中的路径。undo方法是这样的:

        public void undo() {
            //If nothing was drawn, do nothing
            int size = path_history.size();
            if (size == 0)
                return;
            
            //Draw the last saved bitmap
            setupView();
            
            //Loop through saved paths, don't paint last path - remove it
            for (int i=0; i<size-1; i++)
                canvas.drawPath(path_history.get(i), paint);
            path_history.remove(size-1);
            invalidate();
        }

问题是屏幕旋转后这不起作用,因为我重绘了以 90 度角旋转的位图(因此就用户而言,绘图永远不会旋转)。路径被重新绘制,就好像视图处于原始方向一样,因此路径和原始位图不同步。

为了补偿我尝试过:

Matrix m = new Matrix();
m.preRotate(90);
//I TRIED THIS TOO: m.preRotate(90, bitmap width / 2, bitmap height / 2);
for (int i=0; i<size-1; i++)
    path_history.get(i).transform(m);

上面的旋转太糟糕了,甚至没有在屏幕上重绘路径。如果我使用注释掉的旋转,它至少会出现在屏幕上,但仍然很远。如何以与旋转位图相同的方式旋转路径?我在想问题的一部分是我不知道它们从哪个坐标开始旋转我没有找到任何文档。

谢谢!

马特。

4

0 回答 0