我需要获取 imegView 中显示图像的宽度/高度,并将其与 imageView.getImage().getWidth()/getHeight() 中的原始图像大小进行比较,并在用户从应用程序 GUI 中调整其大小时监听更改。
I get this size from imageView.fitWidthProperty()
and similar for height, but I get size of imageView not image within it:
我得到蓝色的大小,即 imageView,但我需要显示图像的大小(绿色)。当用户调整窗口应用程序大小时,如何将其作为属性来侦听(绿色也会更改大小,但它似乎具有最大和最小大小,因此当它是最大或最小时,它会停止使用 imageView 调整大小)。
我使用此属性来计算蓝色矩形下方右下角原始图像大小的百分比。
是否可以?
E:以下是该选项卡的 fxml:
<BorderPane fx:id="root" fx:controller="..."
xmlns:fx="..." xmlns="..." stylesheets="@...css">
<center>
<StackPane>
<ImageView fx:id="..."/>
<fx:include source="...fxml" fx:id="..."/>
</StackPane>
</center>
<bottom>
<VBox fx:id="..." minHeight="110" styleClass="small-padding" spacing="5">
<HBox alignment="CENTER_RIGHT" spacing="5">
<fx:include source="...fxml" resources="..."
fx:id="..."/>
</HBox>
<TextArea fx:id="..." promptText="%..." styleClass="-fx-description-text-area"/>
</VBox>
</bottom>
当。。。的时候ImageView
设置为保留纵横比,必须手动计算实际尺寸。至少我还没有找到其他方法。
double aspectRatio = image.getWidth() / image.getHeight();
double realWidth = Math.min(imageView.getFitWidth(), imageView.getFitHeight() * aspectRatio);
double realHeight = Math.min(imageView.getFitHeight(), imageView.getFitWidth() / aspectRatio);
稍微解释一下: getFitHeight/Width 是你的蓝色矩形。保留源图像的长宽比时,蓝色矩形的至少一侧必须与绿色矩形的相应侧具有相同的长度。此外,绿色矩形将始终位于蓝色矩形内部,因此调用Math.min()
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)