Resizes image width preserving the ratio and using higher quality filtering method, cached to improve performance : Image « JavaFX « Java






Resizes image width preserving the ratio and using higher quality filtering method, cached to improve performance

 
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
 
public class Main extends Application {

    @Override
    public void start(Stage stage) {
        stage.setTitle("HTML");
        stage.setWidth(500);
        stage.setHeight(500);
        Scene scene = new Scene(new Group());
        VBox root = new VBox();    

        final ImageView selectedImage = new ImageView();   
        Image image1 = new Image(Main.class.getResourceAsStream("a.jpg"));
        
        selectedImage.setImage(image1);
        selectedImage.setFitWidth(100);
        selectedImage.setPreserveRatio(true);
        selectedImage.setSmooth(true);
        selectedImage.setCache(true);        
        
        root.getChildren().addAll(selectedImage);
        
        scene.setRoot(root);
 
        stage.setScene(scene);
        stage.show();
    }
 
    public static void main(String[] args) {
        launch(args);
    }
}

   
  








Related examples in the same category

1.Resize an Image
2.Load an Image from URL
3.load an image and resize it to width of 100 while preserving its original aspect ratio
4.Load an image and resize it only in one dimension
5.Loading Image from URL
6.defines a viewport into the source image (zoom effect)