2017-01-30 25 views
1

我將打印爲png我的anchorpane:我在我的控制器中加載一個圖像並寫入一些文本,比我想保存整個面板,但我不知道我必須使用哪些工具。將AnchorPane打印爲PNG

URL fxmlpath = this.getClass().getResource("/fxml/ListaNotaSpesa.fxml"); 

FXMLLoader loader = new FXMLLoader(); 
AnchorPane pane= loader.load(fxmlpath); 


Scene scene = new Scene(pane); 

primaryStage.setTitle("Inserisci Note Spese"); 
primaryStage.setScene(scene); 
primaryStage.show(); 

回答

0

您可以使用Node.snapshot

注意到在下一幀這個節點的快照,並當圖像是準備調用 指定的回調方法。 CSS和佈局 將處理節點及其任何子節點之前的 來渲染它。整個目標圖像被清除爲由SnapshotParameters指定的填充 。該節點然後被渲染爲圖像 。

例子:

WritableImage image = anchorPane.snapshot(new SnapshotParameters(), null); 

File file = new File("D:\\anchor.png"); 

ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", file); 
+0

太感謝你了! –