Java 使用setScale和setTranslate(矩阵)

Java 使用setScale和setTranslate(矩阵),java,android,mobile,bitmap,Java,Android,Mobile,Bitmap,在我的Android应用程序中,我有一个加载的图像。使用此图像,用户可以放大、缩小和前后移动图像。目前我一次只能让一个人工作 经过大量的测试,我已经确定,无论我称之为第二,都是有效的 matrix.setScale(zoom, zoom); // this will not work matrix.setTranslate(currentX, currentY); // this will work canvas.drawBitmap(image, matrix, null); 如果我运行所有

在我的Android应用程序中,我有一个加载的图像。使用此图像,用户可以放大、缩小和前后移动图像。目前我一次只能让一个人工作

经过大量的测试,我已经确定,无论我称之为第二,都是有效的

matrix.setScale(zoom, zoom); // this will not work
matrix.setTranslate(currentX, currentY); // this will work
canvas.drawBitmap(image, matrix, null);
如果我运行所有相同的代码,但只是简单地切换setScale秒,那么它将工作,但setTranslate不会

这似乎应该是一个简单的答案。 顺便说一句:用post设置我的代码的方式是不实用的

matrix.postScale();
matrix.postTranslate(); 

提前感谢

当您调用set*()方法时,您将替换矩阵的全部内容。在第一个示例中,只考虑setTranslate()。您需要使用pre*()和post*()方法来组合转换和缩放操作。

响应代码

matrix.setScale(zoom, zoom); // this will not work
matrix.postTranslate(currentX, currentY); // this will work
canvas.drawBitmap(image, matrix, null);

啊,我有一种感觉,它被重置了。虽然它被重置有点奇怪,但似乎它又回到了“设置”的含义。谢谢