How do I resize an imageview image in javafx?(如何在 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 图像的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 javafx 中调整 imageview 图像的大小?
基础教程推荐
- 如何在相机中应用自定义滤镜 [Surfaceview 预览]. 2022-01-01
- 将 Windows 证书导入 Java 2022-01-01
- 在java中使用xpath和selenium解析HTML表格数据 2022-01-01
- JPA惰性列表上的流 2022-01-01
- 将 double 转换为 Int,向下舍入 2022-01-01
- 控制台应用程序中的 Java 键盘输入解析 2022-01-01
- 在springboot中如何给mybatis加拦截器 2023-04-29
- Maven:无效的目标版本:10 2022-01-01
- Java ECDSAwithSHA256 签名长度不一致 2022-01-01
- doFilter()是在servlet的工作完成之前还是之后执行的? 2022-01-01
