0
我是新来的,有点新来java。 我遇到了问题。 我有一个非常简单的程序,试图创建PNG并将它们保存在用户选定的文件夹中。 byteimage是AA专用字节[]:Eclipse代码运行良好,罐子不是
byteimage = bcd.createPNG(300, 140, ColorSpace.TYPE_RGB, Color.BLACK, Color.BLACK);
的setpath()被调用的浏览按钮的动作侦听器内部
private void setPath() {
JFileChooser pathchooser = new JFileChooser();
pathchooser.setMultiSelectionEnabled(false);
pathchooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
pathchooser.setApproveButtonMnemonic(KeyEvent.VK_ENTER);
pathchooser.showDialog(this, "OK");
File f = pathchooser.getSelectedFile();
if (f != null) {
filepath = f.getAbsolutePath();
pathfield.setText(filepath);
}
}
字节至PNG方法看起来像这样:
public void byteToPNG(String filename) {
try {
InputStream in = new ByteArrayInputStream(byteimage);
BufferedImage bufferedimg = ImageIO.read(in);
ImageIO.write(bufferedimg, "png", new File(filename));
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
这种方法如下所示:
byteToPNG(pathfield.getText() + System.getProperty("file.separator") + textfield.getText() + ".png");
textfield.getText()设置png的实际名称。 构造内部,默认文件路径被设置:
filepath = System.getProperty("user.dir");
pathfield.setText(filepath);
的代码运行在Eclipse细,并将其在所需位置产生一个PNG图像。 不幸的是,导出为jar之后,它会启动,但是当按下生成png的按钮时,没有任何反应。我认为在InputStream或BufferedImage有问题,但我有点困惑。
感谢您的回答。字符串文件名是绝对的,我会尝试在终端中运行jar。 – johnpeterman 2012-03-21 21:58:24