title: How to use a FontAwesomeIconView object as a Stage's icon?
body: <p>I am using <a href="https://bitbucket.org/Jerady/fontawesomefx" rel="nofollow noreferrer">FontAwesomeFX</a> for many icons throughout my application. I would like to use them as icons for my <code>Stage</code> as well.</p>
  
  <p>Since <code>FontAwesomeIconView</code> extends <code>GlyphIcon</code> which extends <code>Text</code>, I can not use it as an <code>Image</code> directly.</p>
  
  <p>Is there a way to create a usable <code>Image</code> from a <code>Text</code> object?</p>
  
  <p>I have tried to use <code>snapshot</code>, but I am not familiar with that method and end up with the standard "empty" icon on my stage.</p>
  
  <p>Here is the MCVE I have so far:</p>
  
  <pre><code>import de.jensd.fx.glyphs.fontawesome.FontAwesomeIcon;
  import de.jensd.fx.glyphs.fontawesome.FontAwesomeIconView;
  import javafx.application.Application;
  import javafx.geometry.Insets;
  import javafx.geometry.Pos;
  import javafx.scene.Scene;
  import javafx.scene.SnapshotParameters;
  import javafx.scene.image.WritableImage;
  import javafx.scene.layout.VBox;
  import javafx.stage.Stage;
  
  public class FontAwesomeIconExample extends Application {
  
      public static void main(String[] args) {
          launch(args);
      }
  
      @Override
      public void start(Stage primaryStage) {
  
          // Simple Interface
          VBox root = new VBox(10);
          root.setAlignment(Pos.CENTER);
          root.setPadding(new Insets(10));
  
          // Convert the FontAwesomeIconView node to an Image
          FontAwesomeIconView iconView = new FontAwesomeIconView(FontAwesomeIcon.ID_CARD_ALT);
          WritableImage icon = iconView.snapshot(new SnapshotParameters(), null);
  
          primaryStage.getIcons().add(icon);
  
          // Show the stage
          primaryStage.setWidth(300);
          primaryStage.setHeight(100);
          primaryStage.setScene(new Scene(root));
          primaryStage.setTitle("Sample");
          primaryStage.show();
      }
  }
  </code></pre>
  
  <p>And the result:</p>
  
  <p><a href="https://i.stack.imgur.com/sVY8j.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sVY8j.png" alt="screenshot"></a></p>
  
  <hr>
  
  <p>Is it possible to use a node snapshot as a stage icon? Or is there a better method of converting the <code>FontAwesomeIconView</code> for this purpose?</p>
  
  <blockquote>
    <p><strong>EDIT:</strong></p>
  </blockquote>
  
  <p>I have tried both Sedrick's and JKostikiadis's methods and both give similar results for me.</p>
  
  <hr>
  
  <p><strong>Sedrick's:</strong></p>
  
  <pre><code>    // Convert the FontAwesomeIconView node to an Image
      FontAwesomeIconView iconView = new FontAwesomeIconView(FontAwesomeIcon.AMAZON);
      WritableImage icon = iconView.snapshot(new SnapshotParameters(), null);
      java.awt.image.BufferedImage bImage = SwingFXUtils.fromFXImage(icon, null);
      ByteArrayOutputStream s = new ByteArrayOutputStream();
      try {
          javax.imageio.ImageIO.write(bImage, "png", s);
      } catch (IOException e) {
          e.printStackTrace();
      }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/l1eYD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/l1eYD.png" alt="screenshot"></a></p>
  
  <hr>
  
  <p><strong>JKostikiadis's:</strong></p>
  
  <pre><code>    FontAwesomeIconView iconView = new FontAwesomeIconView(FontAwesomeIcon.AMAZON);
      WritableImage writableImg = iconView.snapshot(null, null);
      Image img = SwingFXUtils.toFXImage(SwingFXUtils.fromFXImage(writableImg, null), null);
      primaryStage.getIcons().add(img);
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/klv1s.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/klv1s.png" alt="screenshot"></a></p>
  
  <hr>
  
  <p>I believe they both accomplish essentially the same thing (with the sizing of the <code>Image</code> resulting in different displayed icons).</p>
  
  <p>What I do not understand now, is why this is the icon it is producing for me and not them... </p>
  
  <blockquote>
    <p>I am running Windows 7 and JDK 1.8.0_161.</p>
  </blockquote>