Hallo,
Wollte über einen FileChooser ein Directory bestimmen um ein bild rein zu Speichern.
Leider Funktioniert das nur, wenn ich den Pfad vom FileChooser weglasse und das Bild ins Projekt gespeichert wird (Arbeite mit Eclipse und dieser Projekt-Ordner ist gemeint).
Hier der Code:
[JAVA=274]Action saveImgAction = new AbstractAction("Bild Speichern...") {
public void actionPerformed(ActionEvent e) {
int returnVal = fc.showSaveDialog(InfoPanelWindow.this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
fi.format("%04d", fcount);
File file = new File(fc.getSelectedFile().getPath()
+ "/Apfelmaennchen-" + sb.toString() + ".png");
fcount++;
sb.delete(0, sb.length());
int bw = 2560;
int bh = (int) Math.floor(2560 * (bildd.height / (double)bildd.width));
BufferedImage bild = new BufferedImage(bw, bh,
BufferedImage.TYPE_INT_ARGB);
Graphics2D bg = bild.createGraphics();
for (int x = 0; x < bw; x++) {
for (int y = 0; y < bh; y++) {
double cr = ((imgw) * ((double) x) / bw)
+ x2, ci = ((imgh) * ((double) y) / bh)
+ y2;
int p = (isj) ? calcpoint(kjr, kji, cr, ci)
: calcpoint(cr, ci);
bg.setColor(calccolor(p));
bg.fillRect(x, y, 1, 1);
}
}
try {
ImageIO.write(bild, "png", file);
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
};[/code]
So gibt es immer:
es funktioniert nur, wenn ich es zu folgendem ändere:
[JAVA=279]File file = new File("Apfelmaennchen-" + sb.toString() + ".png");[/code]
wie kann ich es machen, dass ich doch überall wo ich will speichern kann??
cu
Wollte über einen FileChooser ein Directory bestimmen um ein bild rein zu Speichern.
Leider Funktioniert das nur, wenn ich den Pfad vom FileChooser weglasse und das Bild ins Projekt gespeichert wird (Arbeite mit Eclipse und dieser Projekt-Ordner ist gemeint).
Hier der Code:
[JAVA=274]Action saveImgAction = new AbstractAction("Bild Speichern...") {
public void actionPerformed(ActionEvent e) {
int returnVal = fc.showSaveDialog(InfoPanelWindow.this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
fi.format("%04d", fcount);
File file = new File(fc.getSelectedFile().getPath()
+ "/Apfelmaennchen-" + sb.toString() + ".png");
fcount++;
sb.delete(0, sb.length());
int bw = 2560;
int bh = (int) Math.floor(2560 * (bildd.height / (double)bildd.width));
BufferedImage bild = new BufferedImage(bw, bh,
BufferedImage.TYPE_INT_ARGB);
Graphics2D bg = bild.createGraphics();
for (int x = 0; x < bw; x++) {
for (int y = 0; y < bh; y++) {
double cr = ((imgw) * ((double) x) / bw)
+ x2, ci = ((imgh) * ((double) y) / bh)
+ y2;
int p = (isj) ? calcpoint(kjr, kji, cr, ci)
: calcpoint(cr, ci);
bg.setColor(calccolor(p));
bg.fillRect(x, y, 1, 1);
}
}
try {
ImageIO.write(bild, "png", file);
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
};[/code]
So gibt es immer:
Code:
java.io.FileNotFoundException: /Users/sebikeller/Schreibtisch/Apfelmaennchen-0000.jpg (No such file or directory)
at java.io.RandomAccessFile.open(Native Method)
at java.io.RandomAccessFile.<init>(RandomAccessFile.java:212)
at javax.imageio.stream.FileImageOutputStream.<init>(FileImageOutputStream.java:53)
at com.sun.imageio.spi.FileImageOutputStreamSpi.createOutputStreamInstance(FileImageOutputStreamSpi.java:37)
at javax.imageio.ImageIO.createImageOutputStream(ImageIO.java:393)
at javax.imageio.ImageIO.write(ImageIO.java:1520)
at Apfelmann$InfoPanelWindow$4.actionPerformed(Apfelmann.java:300)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2028)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2351)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6348)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6113)
at java.awt.Container.processEvent(Container.java:2085)
at java.awt.Component.dispatchEventImpl(Component.java:4714)
at java.awt.Container.dispatchEventImpl(Container.java:2143)
at java.awt.Component.dispatchEvent(Component.java:4544)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4618)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4282)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4212)
at java.awt.Container.dispatchEventImpl(Container.java:2129)
at java.awt.Window.dispatchEventImpl(Window.java:2475)
at java.awt.Component.dispatchEvent(Component.java:4544)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:635)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.imageio.ImageIO.write(ImageIO.java:1529)
at Apfelmann$InfoPanelWindow$4.actionPerformed(Apfelmann.java:300)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2028)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2351)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6348)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6113)
at java.awt.Container.processEvent(Container.java:2085)
at java.awt.Component.dispatchEventImpl(Component.java:4714)
at java.awt.Container.dispatchEventImpl(Container.java:2143)
at java.awt.Component.dispatchEvent(Component.java:4544)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4618)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4282)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4212)
at java.awt.Container.dispatchEventImpl(Container.java:2129)
at java.awt.Window.dispatchEventImpl(Window.java:2475)
at java.awt.Component.dispatchEvent(Component.java:4544)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:635)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
es funktioniert nur, wenn ich es zu folgendem ändere:
[JAVA=279]File file = new File("Apfelmaennchen-" + sb.toString() + ".png");[/code]
wie kann ich es machen, dass ich doch überall wo ich will speichern kann??
cu
Zuletzt bearbeitet: