如何使用JavaFX完成Android ImageView myImage = new ImageView("https://example.com/image/my_image.png");
//maybe
//myImage.scaleType = "centerCrop";
?
我有我的图片视图:
{{1}}
答案 0 :(得分:2)
感谢@TravisF的帖子,我已经实现了最后一个解决方案,使图像始终具有相同的高度,widht和位置(中心)。
double newMeasure = (userImage.getImage().getWidth() < userImage.getImage().getHeight()) ? userImage.getImage().getWidth() : userImage.getImage().getHeight();
double x = (userImage.getImage().getWidth() - newMeasure) / 2;
double y = (userImage.getImage().getHeight() - newMeasure) / 2;
Rectangle2D rect = new Rectangle2D(x, y, newMeasure, newMeasure);
userImage.setViewport(rect);
userImage.setFitWidth(150);
userImage.setFitHeight(150);
userImage.setSmooth(true);