如何以与位图相同的方式旋转路径

时间:2012-03-04 03:38:46

标签: android matrix bitmap android-canvas android-orientation

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

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

        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);

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

谢谢!

0 个答案:

没有答案