Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image 在Java面板中缓冲和显示图像_Image_Io_Graphics2d - Fatal编程技术网

Image 在Java面板中缓冲和显示图像

Image 在Java面板中缓冲和显示图像,image,io,graphics2d,Image,Io,Graphics2d,我正试图使游戏空间入侵者,并希望使用剪贴画作为代表我的外星人和飞船。但是,我不熟悉I/O,因此不了解如何创建BuffereImage,然后使用graphics 2D类来利用我的图像。以下是我的代码片段: public void paintComponent(Graphics g) { super.paintComponent(g); try { img = ImageIO.read(new File("alien.jpg"));

我正试图使游戏空间入侵者,并希望使用剪贴画作为代表我的外星人和飞船。但是,我不熟悉I/O,因此不了解如何创建BuffereImage,然后使用graphics 2D类来利用我的图像。以下是我的代码片段:

public void paintComponent(Graphics g) {
    super.paintComponent(g);
          try {
            img = ImageIO.read(new File("alien.jpg"));
            int w = img.getWidth(null);
            int h = img.getHeight(null);
            BufferedImage alien = 
            new BufferedImage(w,h,BufferedImage.TYPE_INT_ARGB);
            g = alien.getGraphics();
            g.drawImage(img, x, y, null);
          } 
          catch (IOException e) {
            e.printStackTrace();
          }
      }

你真正的问题是什么?我没有发现您的代码中有任何重大问题。感谢您的回复!我运行这个时没有看到图像。我在想路径可能有问题?可能有。路径应该像“C:\images\alien.jpg”一样满,或者可以是“”