简体   繁体   English

使用Java绘制旋转的ImageIcon

[英]Draw rotated ImageIcon using Java

I have ImageIcon face , I don't know how to use command rotate to rotate player face. 我有ImageIcon face ,我不知道如何使用命令rotate来旋转玩家的face。 I know that the rotation is for point 0, 0 . 我知道旋转是针对点0, 0 But how to use for rotate only one item? 但是如何仅用于旋转一项?

My code is: 我的代码是:

int size = 40;
int angle = getAngle(); // in degree...

g2.rotate(Math.toRadians((double)angle); //????????
g2.drawImage(face.getImage(), size * col, size * row, null);

Can anyone advise me? 谁能告诉我?

Thank you. 谢谢。

You can use the Rotated Icon class to change the degrees of rotation of the Icon when painting it. 绘制图标时,可以使用Rotated Icon类来更改Icon旋转度。 The RotatedIcon class can be used to rotate an Icon on any component that uses Icons. RotatedIcon类可用于在使用图标的任何组件上旋转图标。

You can also custom paint the RotatedIcon on a panel using code like the following: 您也可以使用以下代码自定义在面板上绘制RotatedIcon

1) You would create the Icon something like: 1)您将创建图标,如下所示:

RotatedIcon face = new RotatedIcon(new ImageIcon(...), 0);

2) Then in your painting code you use: 2)然后在绘画代码中使用:

face.paintIcon(this, g2, x, y); // determine you x/y location

3) When you want to rotate the icon you use: 3)要旋转图标时,请使用:

face.setDegrees(...);
panel.repaint(); // then panel where you do the custom painting

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM