Hello everyone,
I am new in JavaFX, I download/installed JDK8 with NB.
I am trying to save a scene as image (png or jpg), but the result png is blank. Wondering why?
Can any expert point out what is wrong with my simple code?
Thanks!!!
Here is the Java simple code:
----------------------------------------------------------------------------
import java.io.File;
import static javafx.application.Application.launch;
import javafx.embed.swing.SwingFXUtils;
import javafx.print.PrinterJob;
import javafx.scene.Scene;
import javafx.scene.SnapshotParameters;
import javafx.scene.image.WritableImage;
import javax.imageio.ImageIO;
public class WebViewTest2 extends javafx.application.Application {
private Scene scene = null;
@Override
public void start(javafx.stage.Stage primaryStage) {
try
{
String myURI = "file:///C:\\PSB\\JavaFXApplication1\\src\\hello2.html";
// create WebView with specified local content
final javafx.scene.web.WebView myBrowser = new javafx.scene.web.WebView();
myBrowser.getEngine().load(myURI);
myBrowser.setZoom(javafx.stage.Screen.getPrimary().getDpi() / 96);
primaryStage.setTitle("HTML Hello");
Scene myScene = new javafx.scene.Scene(myBrowser, 1100, 820);
primaryStage.setScene(myScene);
primaryStage.show();
WritableImage mySnapShot = myScene.snapshot(null);
File outImageFile = new File("C:\\PSB\\JavaFXApplication1\\src\\test11.png");
ImageIO.write(SwingFXUtils.fromFXImage(mySnapShot, null), "png", outImageFile);
}
catch (Exception e)
{
}
}
public static void main(String[] args) {
launch(args);
}
}