0

I'm trying to save a modified image as a jpg, but I think I'm completely turned around on how to do it. here's my code so far..

BufferedImage filteredImage = f.filter(image);

        JFileChooser save = new JFileChooser();
        try {
            // retrieve image
            BufferedImage bi = filteredImage;
            File outputfile = new File("image.jpg");
            ImageIO.write(bi, "jpg", outputfile);
            save.showSaveDialog(save);
        } 
        catch (IOException e2) {

        }

The save window opens, but the field is blank and does not save anything. Any idea what I'm doing wrong?

user2792660
  • 37
  • 1
  • 1
  • 9
  • 1) For better help sooner, post an [SSCCE](http://sscce.org/). 2) One way to get image(s) for an example is to hot-link to the images seen in [this answer](http://stackoverflow.com/a/19209651/418556). 3) Always copy/paste error & exception output. 4) You might also link to an example source image and the result this code produces. – Andrew Thompson Nov 27 '13 at 00:41
  • You are showing the save dialog *after* you write your image. How do you expect that to work? – Harald K Nov 27 '13 at 10:03
  • Do not use the JFileChooser as the parent of its own dialog. If you have an application window, use that; otherwise, pass null. – VGR Nov 28 '13 at 23:59

1 Answers1

0

You could start by changing in your write method the second argument from "jpg" to "JPEG".

But my best advice would be to use png format instead, as in the oracle tutorial.

EBoulben
  • 36
  • 3