ImageIO.write无法正常工作? [英] ImageIO.write not working?

查看:191
本文介绍了ImageIO.write无法正常工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写3D绘画,但是在Java中发现了一个问题. 在代码的一部分中,它起作用了:

I'm writing a 3D paint and I found a problem in 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.

哦,现在工作很好,谢谢

Ohhh working fine now thanks

推荐答案

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

代替:

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

这篇关于ImageIO.write无法正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆