java旋转图像函数

lsmd5eda  于 2021-07-03  发布在  Java
关注(0)|答案(1)|浏览(230)

**结束。**此问题需要详细的调试信息。它目前不接受答案。
**想改进这个问题吗?**更新问题,使其成为堆栈溢出的主题。

5年前关门了。
改进这个问题
我怎样才能使这个代码工作??

public class Tutorial extends Applet{

/////////////////DRAWING IMAGES TO THE SCREEN///////////////////////
private Image spiral = null;

public void paint (Graphics g){
    this.setSize(640, 480);

    if (spiral == null){
        spiral = getImage("spiral.jpg");
        spiral.rotateImage(45, this);  //It says that rotateImage is undefined for the Image
    }

    Graphics2D g2 = (Graphics2D)g;
    g2.drawImage(spiral, 25, 50, this);
}

public Image getImage(String path){
    Image tempImage = null;
    try
    {
        URL imageURL = Tutorial.class.getResource(path);
        tempImage = Toolkit.getDefaultToolkit().getImage(imageURL);
    }
    catch (Exception e)
    {
        System.out.println("An error occured - " + e.getMessage());
    }
    return tempImage;
}

////////////////////////////////////////////////////////////////////

///////////////////IMAGE ROTATION /////////////////////////////////

public void rotateImage(double degrees, ImageObserver o){
    ImageIcon icon = new ImageIcon(this.spiral);
    BufferedImage blankCanvas = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = (Graphics2D)blankCanvas.getGraphics();
    g2.rotate(Math.toRadians(degrees), icon.getIconWidth()/2, icon.getIconHeight()/2);
    g2.drawImage(this.spiral, 0, 0, o);
    this.spiral = blankCanvas;
}
/////////////////////////////////////////////////////////////////
}

我知道我必须改变方法rotateimage或图像类型,但我不能真正成功。在这个问题上我有点离题。有什么帮助吗?

ua4mk5z4

ua4mk5z41#

改变

if (spiral == null){
    spiral = getImage("spiral.jpg");
    spiral.rotateImage(45, this);
}

if (spiral == null){
    spiral = getImage("spiral.jpg");
    rotateImage(45, this);
}

rotateImage 你自己的方法不是 Image 方法

相关问题