macos从OSX上的Java程序保存PNG
我的程序允许用户创建并保存一个“布局”文件(一个包含矩形坐标的简单txt文件),然后还保存该布局的PNG图形
在linux、Windows和大多数Mac上,根本没有问题。 然而,我从mac用户那里收到一些报告,他们说png图像不会保存。(遗憾的是,还没有关于他们正在运行的osx版本的信息。)
保存PNG文件示例代码:
JFileChooser fc = new JFileChooser();
fc.setCurrentDirectory(new File(System.getProperty("user.dir")));
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
final int returnVal = fc.showSaveDialog(fc);
if (returnVal == JFileChooser.APPROVE_OPTION) {
String directory = fc.getSelectedFile().toString();
//here I create a buffered image of the layout, bi
//set the image file name to be the selected directory plus the rect label
String str = directory + "/" + s.getLabel();
try {
String path = new File(str + a + ".PNG").getAbsolutePath();
ImageIO.write(bi, "PNG", new File(path));
} catch (IOException ie) {
ie.printStackTrace();
}
}
}
我之前确实有读/写权限的问题(如果没有管理员权限,java无法写入系统目录)但我认为这没有关系。在这些特殊情况下,我知道他们可以写入此文件夹,因为他们可以将布局文件保存在该文件夹中
共 (0) 个答案