[英]Image IO Write not writing
basically I am trying to save an image I have edited in a JFrame, so I have a menu with the save item and I have an action listener to set up for the save item and everything works fine, the file chooser comes up and I can select where I would like to save it, only thing is when I hit save, its not there. 基本上,我试图保存在JFrame中编辑过的图像,所以我有一个带有保存项的菜单,并且为该保存项设置了一个动作监听器,并且一切正常,出现了文件选择器,我可以选择我想保存的位置,只有当我点击保存时,它才不存在。 Here is my code, am I missing something?
这是我的代码,我缺少什么吗?
if(e.getSource().equals(Save)){
JFileChooser keep = new JFileChooser();
keep.setSelectedFile(new File ("newImage.jpg"));
FileNameExtensionFilter filters = new FileNameExtensionFilter("jpeg", "jpg");
keep.setFileFilter(filters);
File output = keep.getSelectedFile();
int count = keep.showSaveDialog(keep);
BufferedImage out = filteredImage;
if (count == JFileChooser.CANCEL_OPTION){
}
else{
try{
ImageIO.write(out, "jpg", output);
//I put this here to see if I was even reaching the method
System.out.println("writing method");
}catch(Exception d){
}
}
}
So, you get a reference to the selectedFile
... 因此,您可以获得对
selectedFile
的引用。
File output = keep.getSelectedFile();
The you show the dialog... 显示对话框...
int count = keep.showSaveDialog(keep);
BufferedImage out = filteredImage;
Then you try and save the image... 然后您尝试保存图像...
ImageIO.write(out, "jpg", output);
...wait, what?! ...等等,什么?! Assuming that
getSelectedFile
isn't null
, how do you know where you're actually saving the image? 假设
getSelectedFile
不为null
,您如何知道实际保存图像的位置?
That process should be reversed slightly... 这个过程应该稍微逆转...
showSaveDialog
if (accepted) {
saveFile = getSelectedFile
ImageIO.write(img, "jpg", saveFile);
}
as a basic psudo code example 作为基本的伪代码示例
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.