如何在javafx中调整imageview图像的大小? [英] How do I resize an imageview image in javafx?

查看:7555
本文介绍了如何在javafx中调整imageview图像的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在JavaFX中将图像调整为特定尺寸,例如100 x 100像素。

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

我如何实现这一目标? Image或ImageView类可以用于此目的吗?

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

推荐答案

是的,使用 ImageView的 。只需致电

Yes, using an ImageView. Just call

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

默认情况下,它不会保留 width:height 比率:您可以使用

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.

这篇关于如何在javafx中调整imageview图像的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆