java旋转图像函数

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

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

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

  1. public class Tutorial extends Applet{
  2. /////////////////DRAWING IMAGES TO THE SCREEN///////////////////////
  3. private Image spiral = null;
  4. public void paint (Graphics g){
  5. this.setSize(640, 480);
  6. if (spiral == null){
  7. spiral = getImage("spiral.jpg");
  8. spiral.rotateImage(45, this); //It says that rotateImage is undefined for the Image
  9. }
  10. Graphics2D g2 = (Graphics2D)g;
  11. g2.drawImage(spiral, 25, 50, this);
  12. }
  13. public Image getImage(String path){
  14. Image tempImage = null;
  15. try
  16. {
  17. URL imageURL = Tutorial.class.getResource(path);
  18. tempImage = Toolkit.getDefaultToolkit().getImage(imageURL);
  19. }
  20. catch (Exception e)
  21. {
  22. System.out.println("An error occured - " + e.getMessage());
  23. }
  24. return tempImage;
  25. }
  26. ////////////////////////////////////////////////////////////////////
  27. ///////////////////IMAGE ROTATION /////////////////////////////////
  28. public void rotateImage(double degrees, ImageObserver o){
  29. ImageIcon icon = new ImageIcon(this.spiral);
  30. BufferedImage blankCanvas = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
  31. Graphics2D g2 = (Graphics2D)blankCanvas.getGraphics();
  32. g2.rotate(Math.toRadians(degrees), icon.getIconWidth()/2, icon.getIconHeight()/2);
  33. g2.drawImage(this.spiral, 0, 0, o);
  34. this.spiral = blankCanvas;
  35. }
  36. /////////////////////////////////////////////////////////////////
  37. }

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

ua4mk5z4

ua4mk5z41#

改变

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

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

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

相关问题