本文介绍了中心裁剪图像JavaFX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用JavaFX完成Android scaleType =centerCrop
?
How can I accomplish Android scaleType="centerCrop"
using JavaFX?
我有我的图像视图:
ImageView myImage = new ImageView("https://example.com/image/my_image.png");
//maybe
//myImage.scaleType = "centerCrop";
推荐答案
感谢@TravisF的帖子,我已经实现了最后的解决方案,使图像始终具有相同的高度,widht和位置(中心)。
Thanks to @TravisF for the post, I've implemented the last solution to make the image always has the same height, widht and position (center).
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);
这篇关于中心裁剪图像JavaFX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!