Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
708 views
in Technique[技术] by (71.8m points)

java - How do I resize an imageview image in javafx?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...