为什么我的图像不旋转?

时间:2015-02-15 19:38:54

标签: java rotation applet bufferedimage graphics2d

此代码显示徽标,但没有旋转。我错过了什么吗?我一直试图旋转很长一段时间。一切都很好,计算正确,但图像显示为普通图像

    import javax.swing.JApplet;
import java.awt.Graphics2D;
import java.awt.Graphics;
import java.applet.Applet;
import java.awt.Font;
import java.awt.image.*;
import java.awt.Image;
import java.awt.geom.*;
import java.awt.Color;
import java.io.*;
import javax.imageio.ImageIO;


public class Display extends Applet
{
static Image logo;
static double rotation;


public void init()
{
    logo = getImage( getCodeBase() , "logo.jpg" );
    rotation = 90;
    setBackground(Color.WHITE);

}

public void paint(Graphics g)
{
    g.drawImage( rotateGear(this), 0 , 0 , this);

}

public static Image rotateGear(ImageObserver o)
{
    BufferedImage bf = new BufferedImage( 400 , 400 , BufferedImage.TYPE_INT_ARGB );
    Graphics2D g2d = bf.createGraphics();
    g2d.drawImage(logo, 0, 0, o);
    g2d.setColor(Color.red);
    g2d.fillRect(390, 390, 10, 10);
    AffineTransform at = new AffineTransform();
    at.rotate(rotation, 178, 178);
    g2d.setTransform(at);
    System.out.println( Math.toRadians(rotation));
    return bf;


}
}

1 个答案:

答案 0 :(得分:1)

因为您在绘制图像后设置了变换。反过来做吧!

(我试过了,否则你的代码工作正常。)