JAVA的rotate怎么用,java如何利用rotate旋转图片_如何在Java中旋转图形
I have drawn some Graphics in a JPanel, like circles, rectangles, etc.
But I want to draw some Graphics rotated a specific degree amount, like a rotated ellipse. What should I do?
解決方案
If you are using plain Graphics, cast to Graphics2D first:
Graphics2D g2d = (Graphics2D)g;
To rotate an entire Graphics2D:
g2d.rotate(Math.toRadians(degrees));
//draw shape/image (will be rotated)
To reset the rotation (so you only rotate one thing):
AffineTransform old = g2d.getTransform();
g2d.rotate(Math.toRadians(degrees));
//draw shape/image (will be rotated)
g2d.setTransform(old);
//things you draw after here will not be rotated
Example:
class MyPanel extends JPanel {
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D)g;
AffineTransform old = g2d.getTransform();
g2d.rotate(Math.toRadians(degrees));
//draw shape/image (will be rotated)
g2d.setTransform(old);
//things you draw after here will not be rotated
}
}
總結(jié)
以上是生活随笔為你收集整理的JAVA的rotate怎么用,java如何利用rotate旋转图片_如何在Java中旋转图形的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 做梦梦到和陌生人接吻什么意思
- 下一篇: 怀孕梦到发大水怎么回事