2014-01-17 101 views
1

我想作爲JavaFX的圖像OPS頁面上指出,將圖像保存到我的文件系統:http://docs.oracle.com/javafx/2/image_ops/jfxpub-image_ops.htm,但我不斷收到此異常錯誤:如何將圖像保存到Mac上的JavaFX文件系統?

java[80783:707] [JRSAppKitAWT markAppIsDaemon]: Process manager already initialized: can't fully enable headless mode. 

這個計算器問題有點幫助JavaFX screencapture headless exception on OSX但我仍然堅持保存圖像。

任何我可以去保存圖像?

這是我當前如何做它:

File outFileImage = new File(imageUrl); 

Toolkit tk = java.awt.Toolkit.getDefaultToolkit().getDefaultToolkit(); 
try { 
    ImageIO.write(SwingFXUtils.fromFXImage(image, null), ".png", outFileImage); 
} catch (Exception e) { 
    log.log(Level.WARNING, "Image not saved to disk", e); 
} 


編輯

我試圖運行Java 8,看看問題是否會得到解決,但我一直得到的JavaFX FXML錯誤:

javafx.fxml.LoadException: Root hasn't been set. Use method setRoot() before load. 
/Users/jonathan/Projects/Dominion/target/classes/dominion/application/controller/main_overview_tab.fxml:13 

at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2613) 
at javafx.fxml.FXMLLoader.access$100(FXMLLoader.java:104) 
at javafx.fxml.FXMLLoader$RootElement.constructValue(FXMLLoader.java:1320) 
at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:740) 
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2723) 
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2527) 
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441) 
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409) 
at dominion.application.controller.MainOverviewTab.initView(MainOverviewTab.java:64) 


編輯

我已經發布這個JavaFX的FXML加載問題到另一個問題在這裏找到:Root hasn't been set Error with Java 8 Eclipse

+0

儘管出現錯誤信息,您的圖片是否正確書寫?還是您只關注該信息? – haraldK

+0

不,圖像未保存到磁盤 –

回答

2

在評論RT-20784 Mac: Headless environment issue, MacOSX,這是關係到你粘貼到你的問題的警告消息,開發者備註:

This indeed requires fixes in JDK. We don't have plans to back port these specific changes to 7uX releases because they are somewhat risky, and we don't want to destabilize the 7uX branch. As Steve suggests, please move to 8.

AFAIK, apart from the fact that FX forces the AWT to run in the headless mode, nothing else changes or breaks because of this. So you may assume that the warning printed out to the console is the only side-effect of the missing changes. As long as you don't need to use AWT/Swing in your application, you should be safe.

因此,也許你最好的行動方針是儘量Java 8,看看您是否仍然有任何問題。

基於新的問題更新關於setRoot()

你得到什麼構建Java 8的FXML錯誤?根據這個Bug Report,這個特殊的「Root未被設置」FXML加載錯誤可能已經在JavaFX 8b121中得到修復。可能會看到related StackOverflow question on setRoot errors。 FXML加載問題與將圖像保存到文件系統的原始問題無關,通常不相關的問題最好作爲新問題提出。

+0

已更新的問題 –

+0

已更新的回答。 – jewelsea

+0

更新的問題。 –

相關問題