用Java重置Graphics2D对象 [英] Reset Graphics2D object in Java
本文介绍了用Java重置Graphics2D对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在用Java进行Graphics2D的实验.但是像往常一样,我被困住了. :P问题是: 假设我有这段代码,
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.
推荐答案
您要做的就是恢复转换.
What you'll want to do is restore the transform.
尝试
AffineTransform oldXForm = g.getTransform();
g.rotate(...);
g.drawLine(...);
g.setTransform(oldXForm); // Restore transform
g.drawLine(...);
这篇关于用Java重置Graphics2D对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文