Java - 无法正确写入图像

时间:2014-03-07 16:11:38

标签: java image image-processing

我使用以下代码制作3张图片0.png,1.png和2.png,但会发生的情况是三个文件分别为1,2,3,但它们不是图像,而在picasa中则说是无效的文件。代码:

private void StartActionPerformed(java.awt.event.ActionEvent evt) {                                      
        for(int i=0; i<3; i++){
            Numbers.setText(""+i);

            BufferedImage image = null;
            try {
                image = new Robot().createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
            } catch (AWTException ex) {
                Logger.getLogger(Flash_Cards.class.getName()).log(Level.SEVERE, null, ex);
            }
            try {
                ImageIO.write(image, "png", new File("E:/Data/" + i));
            } catch (IOException ex) {
                Logger.getLogger(Flash_Cards.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

1 个答案:

答案 0 :(得分:0)

将行更改为:ImageIO.write(image, "png", new File("E:/Data/abc" + i + ".png"));