title: How to save Image in a user selected format using FileChooser in javaFx?
body: <p>I am trying to save image in a user selected format from FileChooser SaveDialog. Here's my code:</p>
  
  <p><a href="https://docs.oracle.com/javase/8/javafx/api/javafx/stage/FileChooser.html#setSelectedExtensionFilter-javafx.stage.FileChooser.ExtensionFilter-" rel="nofollow noreferrer">java docs says the same thing for both get and set methods</a>  I dont get it.</p>
  
  <pre><code>    File f1 = new File("C:\\Users\\KIRAN\\Desktop\\Andromeda1.png");
  
      FileChooser stegoImageSaver = new FileChooser();
      stegoImageSaver.setTitle("Save Image File");
      stegoImageSaver.setInitialDirectory(new File("C:\\"));
      stegoImageSaver.getExtensionFilters().addAll(
          new FileChooser.ExtensionFilter("PNG Files", "*.png"),
          new FileChooser.ExtensionFilter("BMP Files", "*.bmp"),
          new FileChooser.ExtensionFilter("GIF Files", "*.gif"));
      File f1 = stegoImageSaver.showSaveDialog(null);
  
      ImageIO.write(img, "png", f1);
  </code></pre>
  
  <p>What i need is to get the extension from user from the "filechooser save dialog"
  and write the image with that extension.</p>
  
  <p>I don't know how to use get&amp;set extension methods in Filechooser in javaFx and couldn't find the practical implementation.</p>
  
  <p>See my last line of code:  I want to know how to change the "png" to whatever extension selected by the user from the "fileChooser save dialog".</p>
  
  <p>Thanks in advance.</p>