I need to convert SVG file to a javafx.Image. I try:
WebView wb = new WebView();
wb.getEngine().load(Funciones.class.getResource("/com/img/Dibujo.svg").toExternalForm());
wb.setMinSize(125, 125);
wb.setMaxSize(125, 125);
wb.setPrefSize(125, 125);
Scene scene = new Scene(wb);
WritableImage img = new WritableImage(125, 125);
scene.snapshot(img);
File file = new File("CanvasImage.png");
try {
ImageIO.write(SwingFXUtils.fromFXImage(img, null), "png", file);
}
catch (Exception s) {
}
But always, I get a white image. I use webview in some panels to load's svg and works fine, but I don't know why not works to write to a file.
NOTE: I show a stage with webview control, and Image loads OK, but I discover that fails on save to file, because webview load content take place in a thread so I need to control when load is finish, but I don't know how.