Search code examples
javaimagejavafxresizeimage-resizing

Which image formats can be resized in JavaFX


There are about 100 jpeg & png color images used in our JavaFX-built desktop app which, when the window is resized, become stretched and blurry so I'd like to have all the graphics remade in a format that will allow them to be dynamically resized without losing quality. What image format or procedure should be used to do this?

Currently, each image is simply in an ImageView and resized as follows, but I'm open to other suggestions:

if(isSmall){
    Rectangle2D visualBounds = Screen.getPrimary().getVisualBounds();
    double sh = visualBounds.getHeight();
    Scale scale = new Scale(sh, sh, 0, 0);
    root.getTransforms().setAll(scale);
}

Solution

  • As has already been mentioned SVG is probably the way to go for you. JavaFX does not support SVG directly but you can find support here javafxsvg and here svg-to-fxml-converter for example.