在Java2D中是否可以移动坐标系?

c0d*_*d3x 2 java-2d coordinate-systems

我需要一个2D坐标系,使用户空间坐标系在屏幕上摆动组件.现在这正是Java2D所做的.但我需要进一步的是移动屏幕和坐标系的相对位置以获得一种滚动.

在Java 2D中,默认后代(0,0)位于左上角,这在计算机图形中很常见.

有可能移动这一点吗?如果是:我该怎么办?

提前致谢.

Ale*_*lex 5

您可以使用translate()函数更改坐标系.例如:

Graphics2D g;                    // Assume this is already initialized
g.drawLine(100, 100, 200, 200);  // Draw in the default coordinate system
g.translate(100.0, 100.0);       // Move the origin down and to the right
g.drawLine(0, 0, 100, 100);      // Draw the same line relative to new origin
Run Code Online (Sandbox Code Playgroud)

您还可以使用scale(),rotate()和shear()来更强大的坐标系转换.有关更多信息,请查看此页面:http://docstore.mik.ua/orelly/java-ent/jfc/ch04_03.htm