簡體   English   中英

JavaFX Node.snapshot()從工作線程調用時凍結線程,想法?

[英]JavaFX Node.snapshot() freezes thread when called from worker thread, ideas?

我需要將javafx.scene.canvas.Canvas寫入javafx.scene.image.WritableImage 我知道javafx.scene.Node中的snapshot()方法將執行此操作,當我位於JavaFX Application線程上時,它的效果很好。

但是我需要從使用javafx.concurrent包的工作線程執行此寫操作。 因此,我有一個javafx.concurrent.Task<V> ,嘗試從其call()方法內call() snapshot() call()方法。 嘗試執行此操作時,線程在調用snapshot()時凍結。

所以我的問題是我可以從使用javafx.concurrent包的工作線程中調用snapshot()嗎?

嘗試Platfrom#runLater()針對此類任務介紹的Platfrom#runLater()http : Platfrom#runLater()

Platform.runLater(new Runnable() {
    public void run() {
        myNode.snapshot(...)
    }
}

您可以從任何線程運行此代碼,但是會根據需要在FX App Thread上調用snapshot()方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM