JPro-one / JPro

The right place to report about bugs or suggest improvements for JPro.
https://www.jpro.one
9 stars 4 forks source link

SVG image loading in ImageView with setPreserveRatio(true) is not working as expacted! #151

Open ctoabidmaqbool opened 1 year ago

ctoabidmaqbool commented 1 year ago

Hi! I think it's more like a JavaFx issue rather then jPro!

The ImageView -> setPreserveRatio(true) is a very nice feature of javafx. But in the case of SVG image, it's not working as expected.

Sample code:

@Override
public void start(Stage stage) throws FileNotFoundException {
    StackPane stackPane = new StackPane();

    Image image = new Image("https://images6.alphacoders.com/317/317793.jpg", true);

    ImageView imageView = new ImageView(new Image("https://www.svgrepo.com/show/512360/image-picture-971.svg"));
    imageView.setFitWidth(300);
    imageView.setFitHeight(400);
    imageView.setPreserveRatio(false);

    image.progressProperty().addListener((observable, oldValue, newValue) -> {
        if ((Double) newValue == 1.0 && !image.isError()) {
            imageView.setImage(image);
            imageView.setPreserveRatio(true);
        }
    });
    image.errorProperty().addListener((observable, oldValue, newValue) -> {
    });
    image.exceptionProperty().addListener((observable, oldValue, newValue) -> {
    });

    stackPane.getChildren().add(imageView);

    Scene scene = new Scene(stackPane);

    stage.setScene(scene);
    stage.show();
}

Simple SVG Image with setPreserveRatio(false): image

JPG image after finish loading: image

Simple SVG Image with setPreserveRatio(true): image