Example usage for javafx.scene.image ImageView setImage

List of usage examples for javafx.scene.image ImageView setImage

Introduction

In this page you can find the example usage for javafx.scene.image ImageView setImage.

Prototype

public final void setImage(Image value) 

Source Link

Usage

From source file:com.imesha.imageprocessor.controllers.MainController.java

/**
 * Show a given BufferedImage in the UI.
 *
 * @param bufferedImage The image to be shown in the UI
 * @param imageView     The JavaFX ImageView element in which the BufferedImage to be shown.
 *//*  www .  j  ava 2 s.  c o  m*/
private static void showImageInUI(final BufferedImage bufferedImage, final ImageView imageView) {
    Platform.runLater(new Runnable() {
        public void run() {
            Image loadedImage = SwingFXUtils.toFXImage(bufferedImage, null);
            imageView.setImage(loadedImage);
            imageView.setPreserveRatio(true);
            imageView.setSmooth(true);
            imageView.setCache(true);
        }
    });
}

From source file:net.rptools.tokentool.util.ImageUtil.java

public static Image composePreview(StackPane compositeTokenPane, Color bgColor, ImageView portraitImageView,
        ImageView maskImageView, ImageView overlayImageView, boolean useAsBase, boolean clipImage) {
    // Process layout as maskImage may have changed size if the overlay was changed
    compositeTokenPane.layout();//from   w  ww . ja  v a2 s . co m
    SnapshotParameters parameter = new SnapshotParameters();
    Image finalImage = null;
    Group blend;

    if (clipImage) {
        // We need to clip the portrait image first then blend the overlay image over it
        // We will first get a snapshot of the portrait equal to the mask overlay image width/height
        double x, y, width, height;

        x = maskImageView.getParent().getLayoutX();
        y = maskImageView.getParent().getLayoutY();
        width = maskImageView.getFitWidth();
        height = maskImageView.getFitHeight();

        Rectangle2D viewPort = new Rectangle2D(x, y, width, height);
        Rectangle2D maskViewPort = new Rectangle2D(1, 1, width, height);
        WritableImage newImage = new WritableImage((int) width, (int) height);
        WritableImage newMaskImage = new WritableImage((int) width, (int) height);

        ImageView overlayCopyImageView = new ImageView();
        ImageView clippedImageView = new ImageView();

        parameter.setViewport(viewPort);
        parameter.setFill(bgColor);
        portraitImageView.snapshot(parameter, newImage);

        parameter.setViewport(maskViewPort);
        parameter.setFill(Color.TRANSPARENT);
        maskImageView.setVisible(true);
        maskImageView.snapshot(parameter, newMaskImage);
        maskImageView.setVisible(false);

        clippedImageView.setFitWidth(width);
        clippedImageView.setFitHeight(height);
        clippedImageView.setImage(clipImageWithMask(newImage, newMaskImage));

        // Our masked portrait image is now stored in clippedImageView, lets now blend the overlay image over it
        // We'll create a temporary group to hold our temporary ImageViews's and blend them and take a snapshot
        overlayCopyImageView.setImage(overlayImageView.getImage());
        overlayCopyImageView.setFitWidth(overlayImageView.getFitWidth());
        overlayCopyImageView.setFitHeight(overlayImageView.getFitHeight());
        overlayCopyImageView.setOpacity(overlayImageView.getOpacity());

        if (useAsBase) {
            blend = new Group(overlayCopyImageView, clippedImageView);
        } else {
            blend = new Group(clippedImageView, overlayCopyImageView);
        }

        // Last, we'll clean up any excess transparent edges by cropping it
        finalImage = autoCropImage(blend.snapshot(parameter, null));
    } else {
        parameter.setFill(Color.TRANSPARENT);
        finalImage = autoCropImage(compositeTokenPane.snapshot(parameter, null));
    }

    return finalImage;
}

From source file:Main.java

@Override
public void start(Stage stage) {
    stage.setTitle("HTML");
    stage.setWidth(500);//  ww  w  . jav  a2  s . c  o  m
    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.setRotate(90);

    root.getChildren().addAll(selectedImage);

    scene.setRoot(root);

    stage.setScene(scene);
    stage.show();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    stage.setTitle("HTML");
    stage.setWidth(500);//  www  .j ava2 s . co  m
    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);

    Rectangle2D viewportRect = new Rectangle2D(40, 35, 110, 110);
    selectedImage.setViewport(viewportRect);

    root.getChildren().addAll(selectedImage);

    scene.setRoot(root);

    stage.setScene(scene);
    stage.show();
}

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    primaryStage.setTitle("Title");
    Group root = new Group();
    Scene scene = new Scene(root, 600, 330, Color.WHITE);

    GridPane gridpane = new GridPane();
    gridpane.setPadding(new Insets(5));
    gridpane.setHgap(10);/*from  w w  w .  j a  v  a  2s  .c om*/
    gridpane.setVgap(10);

    final ImageView imv = new ImageView();
    final Image image2 = new Image(Main.class.getResourceAsStream("a.jpg"));
    imv.setImage(image2);

    imv.setEffect(new SepiaTone()); // default is full (1.0) effect

    final HBox pictureRegion = new HBox();

    pictureRegion.getChildren().add(imv);
    gridpane.add(pictureRegion, 1, 1);

    root.getChildren().add(gridpane);
    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    primaryStage.setTitle("Title");
    Group root = new Group();
    Scene scene = new Scene(root, 600, 330, Color.WHITE);

    GridPane gridpane = new GridPane();
    gridpane.setPadding(new Insets(5));
    gridpane.setHgap(10);//from  ww  w  . j  av  a2s .  c  o  m
    gridpane.setVgap(10);

    final ImageView imv = new ImageView();
    final Image image2 = new Image(Main.class.getResourceAsStream("button.png"));
    imv.setImage(image2);

    final HBox pictureRegion = new HBox();

    pictureRegion.getChildren().add(imv);
    gridpane.add(pictureRegion, 1, 1);

    root.getChildren().add(gridpane);
    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    primaryStage.setTitle("Title");
    Group root = new Group();
    Scene scene = new Scene(root, 600, 330, Color.WHITE);

    GridPane gridpane = new GridPane();
    gridpane.setPadding(new Insets(5));
    gridpane.setHgap(10);/*www .j a  v  a2  s  . com*/
    gridpane.setVgap(10);

    final ImageView imv = new ImageView();
    imv.setFitWidth(100);
    final Image image2 = new Image(Main.class.getResourceAsStream("button.png"));
    imv.setImage(image2);

    final HBox pictureRegion = new HBox();

    pictureRegion.getChildren().add(imv);
    gridpane.add(pictureRegion, 1, 1);

    root.getChildren().add(gridpane);
    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    primaryStage.setTitle("Title");
    Group root = new Group();
    Scene scene = new Scene(root, 600, 330, Color.WHITE);

    GridPane gridpane = new GridPane();
    gridpane.setPadding(new Insets(5));
    gridpane.setHgap(10);//from  www . j a  v  a  2s . c  om
    gridpane.setVgap(10);

    final ImageView imv = new ImageView();
    imv.setPreserveRatio(true);
    final Image image2 = new Image(Main.class.getResourceAsStream("button.png"));
    imv.setImage(image2);

    final HBox pictureRegion = new HBox();

    pictureRegion.getChildren().add(imv);
    gridpane.add(pictureRegion, 1, 1);

    root.getChildren().add(gridpane);
    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:calendarioSeries.vistas.NewSerieController.java

@FXML
public void handleOk() {
    String tituloAux = titulo.getText().replaceAll(" ", "+").toLowerCase();
    String toJson = readUrl(BASE + tituloAux + "&type=series" + "&r=json");
    resultados.getChildren().clear();/*from w  ww . j  a v a 2  s.c  o  m*/
    try {
        JSONObject busqueda = new JSONObject(toJson);
        if (busqueda.getString("Response").equals("True")) {
            JSONArray res = busqueda.getJSONArray("Search");
            resultados.setPrefRows(res.length());
            for (int i = 0; i < res.length(); i++) {
                JSONObject resActual = new JSONObject(res.get(i).toString());
                HBox resultadoActual = new HBox(50);
                resultadoActual.setMaxWidth(Double.MAX_VALUE);
                resultadoActual.setAlignment(Pos.CENTER_LEFT);
                ImageView posterActual = new ImageView();

                try {
                    Image image = new Image(resActual.getString("Poster"));
                    posterActual.setImage(image);
                    posterActual.setFitHeight(240);
                    posterActual.setFitWidth(180);
                    posterActual.setPreserveRatio(false);
                    resultadoActual.getChildren().add(posterActual);
                } catch (IllegalArgumentException e) {
                    //                        System.out.println("Bad url");
                    Image image = new Image(
                            MainApp.class.getResource("resources/no-image.png").toExternalForm());
                    posterActual.setImage(image);
                    posterActual.setFitHeight(240);
                    posterActual.setFitWidth(180);
                    posterActual.setPreserveRatio(false);
                    resultadoActual.getChildren().add(posterActual);
                }

                String details;
                String nomSerie = new String(resActual.getString("Title").getBytes(), "UTF-8");
                String anoSerie = new String(resActual.getString("Year").getBytes(), "UTF-8");
                if (nomSerie.length() > 15) {
                    details = "%-12.12s...\t\t Ao: %-10s";
                } else {
                    details = "%-12s\t\t Ao: %-10s";
                }
                details = String.format(details, nomSerie, anoSerie);
                Label elemento = new Label(details);
                elemento.setMaxWidth(Double.MAX_VALUE);
                elemento.setMaxHeight(Double.MAX_VALUE);
                resultadoActual.getChildren().add(elemento);

                posterActual.setId(resActual.getString("imdbID"));
                posterActual.setOnMouseClicked(new EventHandler<MouseEvent>() {
                    @Override
                    public void handle(MouseEvent event) {
                        ImageView clickedButton = (ImageView) event.getSource();
                        Stage stage = (Stage) clickedButton.getScene().getWindow();
                        Task task = new Task() {
                            @Override
                            protected Object call() throws Exception {
                                mainController.mainApp.scene.setCursor(Cursor.WAIT);
                                Serie toAdd = new Serie(clickedButton.getId());
                                boolean possible = true;
                                for (Serie serie : mainController.getSeries()) {
                                    if (serie.equals(toAdd))
                                        possible = false;
                                }
                                if (possible)
                                    mainController.getSeries().add(toAdd);

                                try {
                                    mainController.populateImagenes();
                                    mainController.showDetallesMes(mainController.getMesActual());
                                } catch (Exception e) {
                                    e.printStackTrace();
                                } finally {
                                    mainController.mainApp.scene.setCursor(Cursor.DEFAULT);

                                    return mainController.getSeries();
                                }
                            }
                        };
                        Thread th = new Thread(task);
                        th.setDaemon(true);
                        th.start();
                        stage.close();
                    }
                });
                resultados.getChildren().add(resultadoActual);
            }
        } else {
            resultados.getChildren().add(new Label("La busqueda no obtuvo resultados"));
        }
    } catch (JSONException e) {
        e.printStackTrace();
    } catch (UnsupportedEncodingException ex) {
        Logger.getLogger(NewSerieController.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:fruitproject.FruitProject.java

public void second(final String pfname) {

    final Stage st = new Stage();
    Scene scene = null;/*w w w.  j  av a 2 s  .  com*/
    final GridPane grid = new GridPane();
    grid.setAlignment(Pos.CENTER);
    grid.setHgap(10);
    grid.setVgap(10);
    grid.setPadding(new Insets(25, 25, 25, 25));
    TableView tv = new TableView();

    final TableColumn<Map, String> firstDataColumn = new TableColumn<>("Name");
    final TableColumn<Map, String> secondDataColumn = new TableColumn<>("Amount");
    final TableColumn<Map, String> thirdDataColumn = new TableColumn<>("Remove");
    firstDataColumn.setMinWidth(130);
    secondDataColumn.setMinWidth(130);
    thirdDataColumn.setMinWidth(130);

    if (!pfname.equals("")) {

        firstDataColumn.setCellValueFactory(new MapValueFactory(Column1MapKey));
        secondDataColumn.setCellValueFactory(new MapValueFactory(Column2MapKey));
        thirdDataColumn.setCellValueFactory(new MapValueFactory(Column3MapKey));

        rows = 0;
        tv = new TableView<>(generateDataInMap(pfname, addPairs));

    }

    tv.getColumns().setAll(firstDataColumn, secondDataColumn, thirdDataColumn);

    // secondDataColumn.setCellFactory(TextFieldTableCell.forTableColumn());

    ScrollPane sp = new ScrollPane();
    sp.setMinWidth(400);
    sp.setHbarPolicy(ScrollBarPolicy.NEVER);
    sp.setContent(tv);
    grid.add(sp, 0, 3);

    final ComboBox comboBox = new ComboBox();
    HBox hb1 = new HBox();
    comboBox.setValue("FILE");
    comboBox.getItems().addAll("Save this file", "Load a new file");
    Button btnOk = new Button();
    btnOk.setText("OK");
    hb1.getChildren().addAll(comboBox, btnOk);
    hb1.setSpacing(10);
    grid.add(hb1, 0, 1);

    Label label1 = new Label("Title:");
    final TextField tfFilename = new TextField();
    tfFilename.setText(getTitle(pfname));
    HBox hb = new HBox();
    hb.getChildren().addAll(label1, tfFilename);
    hb.setSpacing(10);
    grid.add(hb, 0, 2);

    final Stage ps = new Stage();
    final TableView tv1 = tv;
    btnOk.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            //System.out.println("Hello World!");

            if (comboBox.getValue().equals("Load a new file")) {
                first(ps);
                st.close();
            } else {
                PrintWriter pw = null;
                try {
                    pw = new PrintWriter("abc.json");
                    BufferedWriter bw = new BufferedWriter(new FileWriter(pfname, false));
                    bw.write("{title:\"" + tfFilename.getText() + "\"");
                    bw.write(",fruits:[");
                    for (int i = 0; i < rows; i++) {
                        bw.write("{name:\"" + String.valueOf(firstDataColumn.getCellData(i)) + "\",amount:"
                                + String.valueOf(secondDataColumn.getCellData(i)) + "}");
                        if (i != rows - 1)
                            bw.write(",");
                    }
                    bw.write("]}");

                    bw.close();

                } catch (Exception e) {
                    System.out.println(e.toString());
                }

            }
        }
    });

    Button btn = new Button();
    btn.setText("New Fruit");
    grid.add(btn, 1, 2);

    // TableView tv=new TableView();
    // TableColumn Col1 = new TableColumn("Name");
    // TableColumn Col2 = new TableColumn("Amount");
    // TableColumn Col3 = new TableColumn("Remove");
    // tv.getColumns().addAll(Col1, Col2, Col3);

    //sp.setFitToWidth(true);

    Image img = new Image("file:music.jpg");
    ImageView iv2 = new ImageView();
    iv2.setImage(img);
    iv2.setFitWidth(200);
    iv2.setPreserveRatio(true);
    iv2.setSmooth(true);
    iv2.setCache(true);
    grid.add(iv2, 1, 3);

    btn.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            //System.out.println("Hello World!");

            System.out.println(comboBox.valueProperty());
            st.close();
            third(pfname);

        }
    });

    scene = new Scene(grid, 700, 450);
    st.setScene(scene);
    st.show();

}