Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ctoabidmaqbool opened this issue Apr 18, 2023 · 0 comments

Comments

@ctoabidmaqbool
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant