How do I resize an imageview image in javafx?

JavaImageJavafxResizeImageview

Java Problem Overview


I need to resize an image to specific dimensions, 100 by 100 pixels for example, in JavaFX.

How can I achieve that? Could the Image or the ImageView class be used for this purpose?

Java Solutions


Solution 1 - Java

Yes, using an ImageView. Just call

ImageView imageView = new ImageView("...");
imageView.setFitHeight(100);
imageView.setFitWidth(100);

By default, it will not preserve the width:height ratio: you can make it do so with

imageView.setPreserveRatio(true);

Alternately you can resize the Image directly on loading:

Image image = new Image("my/res/flower.png", 100, 100, false, false);

Resizing the image on loading is useful for things like thumbnails of larger images as the memory required is lower than storing the larger image data representation in memory.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJeremyView Question on Stackoverflow
Solution 1 - JavaJames_DView Answer on Stackoverflow