当我尝试对当前的 g2d 对象应用旋转时,它不会旋转它,而是将它呈现在同一个位置(在我的上下文中位于另一个之上)。根据我对旋转方法的理解,它将转换应用于当前图形上下文,转换其后出现的任何渲染的像素(这可能是我出错的地方)。这是有问题的代码:
@Override
public void paint(final Graphics graphics) {
super.paint(graphics);
final Graphics2D g2d = (Graphics2D) graphics;
....
....
g2d.setColor(Color.RED);
g2d.setStroke(new BasicStroke(SMALL_LINE_THICKNESS));
if (isLattice1Drawn) {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1));
// lattice1 and lattice2 are Polygon objects
g2d.draw(lattice1);
// This fades in the second Polygon over the first
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
// This line should rotate it, but doesn't
g2d.rotate(Math.toRadians(210));
g2d.draw(lattice2);
.....
谢谢,迈克
编辑 1 作为 Jeff 的建议,我尝试只进行旋转和绘画,留下以下代码:
@Override
public void paint(final Graphics graphics) {
super.paint(graphics);
final Graphics2D g2d = (Graphics2D) graphics;
g2d.rotate(Math.toRadians(210));
g2d.draw(lattice2);
return;
// Rest of paint .................
不幸的是,这没有帮助,任何其他建议都将受到欢迎。
编辑2:当我不调用旋转时,会渲染多边形,但是当我什么都不做时。谁能解释一下?