How do I resize JavaFX images?
•
Java
I have a JavaFX scene. image. Image, I want to resize it, for example, scale it by a given factor What to do (not converted to bufferedimage), and what are the quality and performance options (such as interpolation type)?
Several questions look similar, but I can't find anyone who asks the same question The key is that the input is an image object (and a scaling factor), and the desired output is another image object
Solution
The simplest way is:
public Image scale(Image source,int targetWidth,int targetHeight,boolean preserveRatio) { ImageView imageView = new ImageView(source); imageView.setPreserveRatio(preserveRatio); imageView.setFitWidth(targetWidth); imageView.setFitHeight(targetHeight); return imageView.snapshot(null,null); }
By calling ImageView Setsmooth (...), which can control the speed / smoothness of the scaling algorithm to a minimum Use slower algorithms, use the value true, use better smoothing, use faster algorithms, and use less smoothing
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码