在 Java 中重置 Graphics2D 对象
我正在用 Java 尝试 Graphics2D。但像往常一样,我被困住了。 :P 问题是: 假设我有这段代码,
Graphics2D g=(Graphics2D)(this.getGraphics()); //Inside a JFrame
g.rotate(Math.PI/8);
g.drawLine(10, 20, 65, 80);
//I want this one and all following lines to be drawn without any rotation
g.drawLine(120, 220, 625, 180);
可能吗???我知道一定有办法,但我无法弄清楚。请帮忙。
I was experimenting with Graphics2D in Java. But as usual, I am stuck. :P The problem is:
Suppose i have this code,
Graphics2D g=(Graphics2D)(this.getGraphics()); //Inside a JFrame
g.rotate(Math.PI/8);
g.drawLine(10, 20, 65, 80);
//I want this one and all following lines to be drawn without any rotation
g.drawLine(120, 220, 625, 180);
Is it possible??? I know there must be some way but I am not able to figure it out. Please help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您要做的就是恢复转换。
尝试
What you'll want to do is restore the transform.
Try
调用
getTransform()
(给您一个副本)、旋转、绘制,然后使用setTransform()
恢复状态。setTransform()
的文档甚至有一个示例。Call
getTransform()
(gives you a copy), rotate, draw, and then usesetTransform()
to restore the state. The docs forsetTransform()
even have an example.