简体   繁体   English

ImageIO.write不工作?

[英]ImageIO.write not working?

I'm writing a 3D paint and I found a problem in java. 我正在写一个3D绘画,我在java中发现了一个问题。 In one part of the code it's working: 在代码的一部分中它正在工作:

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();
} 

While in another one it isn't working: 而在另一个它没有工作:

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();
}

Can you tell me how to make it work? 你能告诉我如何让它发挥作用吗? Thanks Before you ask, yes it does execute that part of the code, I checked. 谢谢在你问之前,是的,它确实执行了那部分代码,我查了一下。

Edit: 编辑:

Ohhh working fine now thanks 哦,工作正常,谢谢

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

代替:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM