JavaFx中图像与显示

import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;

public class App14_7 extends Application {

    @Override
    public void start(Stage primaryStage) {

        //创建图像对象
        Image image = new Image("/image/close.png");
        //创建显示图像的对象
        ImageView imageView = new ImageView(image);
        Button button1 = new Button("您好", imageView);
        Button button2 = new Button("Hello", new ImageView(image));
        // 创建水平面板,其上组件间距为20像素
        HBox hBox = new HBox(20);
        hBox.getChildren().addAll(button1, button2);
        hBox.setAlignment(Pos.CENTER);

        Image im = new Image("/image/close.png");
        ImageView iv2 = new ImageView();
        iv2.setImage(im);
        // 设置图像视图的宽度为80像素
        iv2.setFitHeight(80);
        // 设置保持缩放比例
        iv2.setPreserveRatio(true);
        //设置平滑显示图像
        iv2.setSmooth(true);
        // 设置缓存以提高性能
        iv2.setCache(true);

        ImageView iv3 = new ImageView();
        iv3.setImage(im);
        iv3.setRotate(90);
        iv3.setFitWidth(100);
        iv3.setPreserveRatio(true);

        BorderPane rootPane = new BorderPane();
        rootPane.setBottom(hBox);
        rootPane.setCenter(iv2);
        rootPane.setCenter(iv3);


        Scene scene = new Scene(rootPane, 200, 50);
        primaryStage.setScene(scene);
        primaryStage.setTitle("图像与显示");
        primaryStage.show();

    }

    public static void main(String[] args) {
        Application.launch(args);
    }
}
posted @ 2021-02-15 21:43  xl4ng  阅读(184)  评论(0编辑  收藏  举报