Поворот изображения в цикле - PullRequest
0 голосов
/ 21 мая 2018

У меня проблема с поворотом изображения.Это то, что я пытался, но это не работает.

Любая помощь будет оценена.

@Override
public void paintComponent(Graphics p) {

    BufferedImage arrow = LoadImage("C:\\Users\\Pawel Celuch\\Desktop\\arrow.png");

    super.paintComponent(p);
    Graphics2D g2d = (Graphics2D) p;
    g2d.drawImage(arrow, (int)x, (int)y+550, this);

}

1 Ответ

0 голосов
/ 21 мая 2018

Вы можете использовать метод поворота с углом класса AffineTransform в java.

private double currentAngle = 60.7D;

@Override
protected void paintComponent(final Graphics g) {
     BufferedImage arrow = LoadImage("C:\\Users\\Pawel Celuch\\Desktop\\arrow.png");
    super.paintComponent(g);
    Graphics2D g2d = (Graphics2D) g;
    AffineTransform orgX = g2d.getTransform();
    AffineTransform newX = (AffineTransform) (orgX.clone());
    // adjust center of image view of the panel
    int centX = this.getWidth() / 2;
    int centY = this.getHeight() / 2;
    newX.rotate(Math.toRadians(currentAngle), centX, centY);
    g2d.setTransform(newX);
    g2d.drawImage(arrow, x, y+550, this);
    g2d.setTransform(orgX);

}

Диапазон currentAngle должен быть в диапазоне от 0 до 360 градусов.

enter image description here

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...