Home
Categories
Dictionary
Download
Project Details
FAQ
License

JavaFX to Graphics2D conversion usage



You use the library to convert to Graphics2D by calling one of the convert methods of the Graphics2DConverter class.

For example:
   BuffferedImage image = new BufferedImage(500, 500, BufferedImage.TYPE_INT_ARGB);
   Graphics2D g2d = image.createGraphics();
   Graphics2DConverter converter = new Graphics2DConverter();
   converter.convert(<my JavaFX root>);
   ImageIO.write(image, "png", file);

Parameters

Main Article: ConverterParameters

Several parameters allow to configure the result. For example:
   BuffferedImage image = new BufferedImage(500, 500, BufferedImage.TYPE_INT_ARGB);
   Graphics2D g2d = image.createGraphics();      
   ConverterParameters params = new ConverterParameters();
   params.insets = 10;   
   Graphics2DConverter converter = new Graphics2DConverter(g2d, params);
   converter.convert(<my JavaFX root>);

Handling the viewBox the Graphics2D result

It is possible to set the viewBox of the Graphics2D result and the alignment of the content.

In the following example the result will have the dimension of the root Node content with a specified insets:
   Graphics2DConverter converter = new Graphics2DConverter();
   Rectangle2D rect = converter.getViewbox(<my JavaFX root>);
   int insets = 10;
   image = new BufferedImage((int) rect.getWidth() + insets * 2, (int) rect.getHeight() + insets * 2, BufferedImage.TYPE_INT_ARGB);
      
   Graphics2D g2d = image.createGraphics();
   converter.setGraphics2D(g2d);

   ConverterParameters params = new ConverterParameters();
   params.insets = insets;
   params.allowTransformForRoot = true;
   converter.convert(node, params);
   ImageIO.write(image, "png", file);            

See also


Categories: Tosvg

Copyright 2021-2022 Herve Girod. All Rights Reserved. Documentation and source under the BSD-3-Clause License