How do I resize an imageview image in javafx?

筅森魡賤 提交于 2019-11-26 23:00:25

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/27894945/how-do-i-resize-an-imageview-image-in-javafx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!