javajavafxscreenshotdpihdpi

How to better the DPI quality of the image resulting from a scene scrennshot in JavaFX


What I want to do is take a screenshot of the scene, I achieved this with the following code

    WritableImage snapshot = stage.getScene().snapshot(null);
    File file = new File("src//HE//Utilidades//Imagenes//consul.png");
    try {
        ImageIO.write(SwingFXUtils.fromFXImage(snapshot, null), "png", file);
        //this is for open the screenshot
        Desktop dt = Desktop.getDesktop();
        dt.open(file);

    } catch (IOException e) {
        e.printStackTrace();
    }

The screenshot is perfect the problem I have is with the quality of the screenshot , which i dont know of what dependents , I try to make the scene bigger but the quality of dpi remains the same (70) creating a very unpleasant image, i'm looking a way to improve the dpi of the screenshot at least 300dpi for printing

this is the quality that i get


Solution

  • A simple sceenshot is a screenshot and not a high-resolution rendering of your scene. You will not be able to get more pixels into your image than there are on your screen. So unless you have a 300 DPI screen, then what you want is not possible with a simple screenshot.

    If you want a higher resolution image of your scene then you have to use other techniques like offscreen rendering. An example can be found here:

    http://www.ambracode.com/index/show/1217604