JavaFX - How to create SnapShot/Screenshot of (invisble) WebView

前端 未结 3 1170
轮回少年
轮回少年 2021-02-08 08:27

I want to create a SnapShot/Screenshot/Image from a WebView in JavaFX(8).
This WebView does not need to be visible (in my case).

My question:
Is

3条回答
  •  离开以前
    2021-02-08 08:41

    The class WebView contains the following function:

    private boolean isTreeReallyVisible() {
        if (getScene() == null) {
            return false;
        }
    
        final Window window = getScene().getWindow();
    
        if (window == null) {
            return false;
        }
    
        boolean iconified = (window instanceof Stage) ? ((Stage)window).isIconified() : false;
    
        return impl_isTreeVisible()
               && window.isShowing()
               && window.getWidth() > 0
               && window.getHeight() > 0
               && !iconified;
    }
    

    As long as the function returns false, the rendering is blocked. So it might be quite tricky to get it to render. Normally, for snapshot you don't have to put the Node in the scene at all.

提交回复
热议问题