ImageIO.write无法正常工作?

时间:2013-07-10 19:34:40

标签: java javax.imageio

我正在写3D画,我在java中发现了一个问题。 在代码的一部分中它起作用:

try {
    ImageIcon savePane=new ImageIcon("save.png");
    String FilePath= (String)JOptionPane.showInputDialog(null,"Enter file path and name\n Warning: Instead of one '\\' write '\\\\'", "Save",JOptionPane.PLAIN_MESSAGE,savePane,null,"C:\\\\example.png");
    BufferedImage image = new Robot().createScreenCapture(new Rectangle(110,130,put.getWidth()-3,put.getHeight()));
    ImageIO.write(image, "png", new File(FilePath));    
    System.out.println(FilePath);
} catch (IOException e) { 
    e.printStackTrace();
} catch (HeadlessException e) {
    e.printStackTrace();
} catch (AWTException e) {
    e.printStackTrace();
} 

在另一个中它不起作用:

try {
    String UndoFolder= "was.png";
    BufferedImage image = new Robot().createScreenCapture(new Rectangle(110,130,put.getWidth()-3,put.getHeight()));
    ImageIO.write(image, ".png",new File(UndoFolder));          
} catch (IOException e1) {
    e1.printStackTrace();
} catch (AWTException e1) {
    e1.printStackTrace();
} catch (HeadlessException e3) {
    e3.printStackTrace();
}

你能告诉我如何让它发挥作用吗?谢谢 在你问之前,是的,它确实执行了那部分代码,我检查了。

编辑:

哦,工作正常,谢谢

1 个答案:

答案 0 :(得分:11)

ImageIO.write(image, "png",new File(UndoFolder));

而不是:

ImageIO.write(image, ".png",new File(UndoFolder));