List of usage examples for javafx.scene.image Image Image
public Image(@NamedArg("is") InputStream is, @NamedArg("requestedWidth") double requestedWidth, @NamedArg("requestedHeight") double requestedHeight, @NamedArg("preserveRatio") boolean preserveRatio, @NamedArg("smooth") boolean smooth)
From source file:Main.java
/** * Creates an image canvas with the given width and height. *///from w w w . j a v a 2 s .c o m public static Canvas createImageCanvas(String url, double width, double height) { ImageView img = new ImageView(new Image(url, width, height, false, true)); final Canvas canvas = new Canvas(width, height); final GraphicsContext gc = canvas.getGraphicsContext2D(); gc.drawImage(img.getImage(), 0, 0); return canvas; }
From source file:Main.java
@Override public void start(Stage stage) { stage.setTitle("HTML"); stage.setWidth(500);/* w ww . j a v a2 s. co m*/ stage.setHeight(500); Scene scene = new Scene(new Group()); VBox root = new VBox(); Hyperlink hpl = new Hyperlink("java2s.com"); Image image1 = new Image(new File("a.jpg").toURI().toString(), 0, 100, false, false); hpl.setFont(Font.font("Arial", 14)); hpl.setGraphic(new ImageView(image1)); root.getChildren().addAll(hpl); scene.setRoot(root); stage.setScene(scene); stage.show(); }
From source file:de.digiway.rapidbreeze.client.controller.StatusbarController.java
@Override public void initialize(URL url, ResourceBundle rb) { this.resourceBundle = rb; this.rrb = RRB.get(); this.connectedImage = new Image("images/icons/connected-26.png", 18d, 18d, true, true); this.disconnectedImage = new Image("images/icons/disconnected-26.png", 18d, 18d, true, true); setDisconnected();//w w w. ja v a 2s. c o m }
From source file:spacetrader.controller.EncounterScreenController.java
/** * Initializes the controller class./*from ww w . j a va 2 s .c om*/ */ @Override public void initialize(URL url, ResourceBundle rb) { minuteMatrix = new Array2DRowRealMatrix(MINUTE_ARROW); hourMatrix = new Array2DRowRealMatrix(HOUR_ARROW); context = canvas.getGraphicsContext2D(); context.translate(375, 275); context.setFill(Color.CORNFLOWERBLUE); context.fillPolygon(minuteMatrix.getColumn(0), minuteMatrix.getColumn(1), 10); context.setFill(Color.MEDIUMAQUAMARINE); context.fillPolygon(hourMatrix.getColumn(0), hourMatrix.getColumn(1), 8); timeline = new Timeline(); timeline.setCycleCount(Timeline.INDEFINITE); inCount = 0; upDown = true; KeyFrame frame = new KeyFrame(Duration.seconds(1.0 / 24), new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { System.out.println(inCount); context.clearRect(-375, -275, 750, 550); context.setStroke(Color.rgb(0, outCount, 127 + outCount)); context.setLineWidth(61); context.strokeOval(-230, -230, 460, 460); context.setStroke(Color.rgb(0, (outCount + 30) % 128, 127 + (outCount + 30) % 128)); context.strokeOval(-290, -290, 580, 580); context.setStroke(Color.rgb(0, (outCount + 60) % 128, 127 + (outCount + 60) % 128)); context.strokeOval(-350, -350, 700, 700); context.setStroke(Color.rgb(0, (outCount + 90) % 128, 127 + (outCount + 90) % 128)); context.setLineWidth(100); context.strokeOval(-430, -430, 860, 860); context.setFill(new LinearGradient(-200, -200, 200, 200, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(255, 255 - inCount, inCount)), new Stop(1, Color.rgb(255 - inCount, 0, 255)))); context.fillOval(-200, -200, 400, 400); minuteMatrix = minuteMatrix.multiply(minuteRotateMatrix); hourMatrix = hourMatrix.multiply(hourRotateMatrix); context.setFill(Color.CORNFLOWERBLUE); context.fillPolygon(minuteMatrix.getColumn(0), minuteMatrix.getColumn(1), 10); context.setFill(Color.MEDIUMAQUAMARINE); context.fillPolygon(hourMatrix.getColumn(0), hourMatrix.getColumn(1), 8); if (inCount % 20 < 10) { context.drawImage( new Image(Paths.get("image/star.png").toUri().toString(), 360, 360, false, false), -180, -180); } else { context.drawImage( new Image(Paths.get("image/star.png").toUri().toString(), 300, 300, false, false), -150, -150); } if (upDown) { inCount += 3; if (inCount >= 255) { upDown = false; } } else { inCount -= 3; if (inCount <= 0) { upDown = true; } } if (outCount >= 128) { outCount = 0; } else { outCount += 8; } } }); timeline.getKeyFrames().add(frame); timeline.play(); }
From source file:ijfx.ui.previewToolbar.DefaultWidget.java
@Override public Image getImage(PreviewService previewService, int size) { if (image != null) return image; if (previewService == null) return null; if (previewService.getImageDisplayService().getActiveDataset() == null) { return null; } else if (this.getIcon().equals("preview")) { try {/*from ww w .java2 s. c o m*/ previewService.setParameters(-1, -1, size, size); return previewService.getImageDisplay(action, this.getParameters()); } catch (Exception e) { e.printStackTrace(); FontAwesomeIconView fontAwesomeIconView = new FontAwesomeIconView(FontAwesomeIcon.AMBULANCE); return FontAwesomeIconUtils.FAItoImage(fontAwesomeIconView, size); } } else if (getIcon().startsWith("char:")) { Canvas canvas = new Canvas(size, size); GraphicsContext graphicsContext2D = canvas.getGraphicsContext2D(); graphicsContext2D.setFill(Color.WHITE); graphicsContext2D.setFont(javafx.scene.text.Font.font("Arial", size)); graphicsContext2D.fillText(getIcon().substring(5), size / 3, size * 0.8); final SnapshotParameters params = new SnapshotParameters(); params.setFill(Color.TRANSPARENT); // final WritableImage snapshot = canvas.snapshot(params, null); Task<WritableImage> getIcon = new CallbackTask<Canvas, WritableImage>(canvas) .run(input -> input.snapshot(params, null)); Platform.runLater(getIcon); try { // Image image = new Ima image = getIcon.get(); return image; } catch (InterruptedException ex) { Logger.getLogger(DefaultWidget.class.getName()).log(Level.SEVERE, null, ex); } catch (ExecutionException ex) { Logger.getLogger(DefaultWidget.class.getName()).log(Level.SEVERE, null, ex); } return null; } //Check if icon exist in Enumeration else if (Arrays.stream(FontAwesomeIcon.values()).filter(e -> e.name().equals(icon)).count() > 0) { FontAwesomeIconView fontAwesomeIconView = new FontAwesomeIconView(FontAwesomeIcon.valueOf(icon)); return FontAwesomeIconUtils.FAItoImage(fontAwesomeIconView, size); } else { image = new Image(getClass().getResource(icon).toExternalForm(), size, size, true, true); return image; } }
From source file:org.sleuthkit.autopsy.imageanalyzer.ThumbnailCache.java
/** * generate a new thumbnail for the given file and save it to the disk cache * * @param file//from w ww .ja v a2s .c o m * * @return the newly generated thumbnail {@link Image}, or {@code null} if a * thumbnail could not be generated */ private Image generateAndSaveThumbnail(final DrawableFile<?> file) { //create a buffered input stream for the underlying Abstractfile try (InputStream inputStream = new BufferedInputStream( new ReadContentInputStream(file.getAbstractFile()))) { final Image thumbnail = new Image(inputStream, MAX_ICON_SIZE, MAX_ICON_SIZE, true, true); if (thumbnail.isError()) { //if there was an error loading the image via JFX, fall back on Swing LOGGER.log(Level.WARNING, "problem loading image: " + file.getName() + " .", thumbnail.getException()); return fallbackToSwingImage(file); } else { //if the load went successfully, save the thumbnail to disk on a background thread imageSaver.execute(() -> { saveIcon(file, thumbnail); }); return thumbnail; } } catch (IOException ex) { //if the JX load throws an exception fall back to Swing return fallbackToSwingImage(file); } }
From source file:org.sleuthkit.autopsy.imagegallery.ThumbnailCache.java
/** * generate a new thumbnail for the given file and save it to the disk cache * * @param file// w w w .jav a2 s . c om * * @return the newly generated thumbnail {@link Image}, or {@code null} if a * thumbnail could not be generated */ private Image generateAndSaveThumbnail(final DrawableFile<?> file) { //create a buffered input stream for the underlying Abstractfile try (InputStream inputStream = new BufferedInputStream( new ReadContentInputStream(file.getAbstractFile()))) { final Image thumbnail = new Image(inputStream, MAX_ICON_SIZE, MAX_ICON_SIZE, true, true); if (thumbnail.isError()) { //if there was an error loading the image via JFX, fall back on Swing LOGGER.log(Level.WARNING, "problem loading thumbnail for image: " + file.getName() + " ."); // Doing it this way puts the whole stack trace in the console output, which is probably not // needed. There are a significant number of cases where this is expected to fail (bitmaps, // empty files, etc.) //LOGGER.log(Level.WARNING, "problem loading image: " + file.getName() + " .", thumbnail.getException()); return fallbackToSwingImage(file); } else { //if the load went successfully, save the thumbnail to disk on a background thread imageSaver.execute(() -> { saveIcon(file, thumbnail); }); return thumbnail; } } catch (IOException ex) { //if the JX load throws an exception fall back to Swing return fallbackToSwingImage(file); } }
From source file:photobooth.views.ExplorerPane.java
private BorderPane createImageView(final File imageFile) { // DEFAULT_THUMBNAIL_WIDTH is a constant you need to define // The last two arguments are: preserveRatio, and use smooth (slower) // resizing//from w w w. j ava 2 s . com ExplorerPane explorerPane = this; ImageView imageView = null; BorderPane borderPane = new BorderPane(); try { borderPane.setMaxSize(100, 100); borderPane.setMinSize(100, 100); FileInputStream fileInputStream = new FileInputStream(imageFile); final Image image = new Image(fileInputStream, 100, 100, true, true); imageView = new ImageView(image); fileInputStream.close(); imageView.getStyleClass().add("image-view"); borderPane.setCenter(imageView); //imageView.setFitWidth(80); imageView.setOnMouseClicked(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent mouseEvent) { if (mouseEvent.getButton().equals(MouseButton.PRIMARY)) { if (mouseEvent.getClickCount() == 1) { Global.getInstance().setSceneRoot(LoadingPane.getInstance()); Platform.runLater(() -> { new Thread(new Runnable() { @Override public void run() { ImagePane.getInstance().init(explorerPane, imageFile); Global.getInstance().setSceneRoot(ImagePane.getInstance()); } }).start(); }); } } } }); } catch (FileNotFoundException ex) { ex.printStackTrace(); } catch (IOException ex) { Logger.getLogger(ExplorerPane.class.getName()).log(Level.SEVERE, null, ex); } return borderPane; }
From source file:ui.main.MainViewController.java
@Override public void initialize(URL url, ResourceBundle rb) { //initialiing the main connectionManager = ConnectionManager.getConnectionManager(); contactsManager = new ContactsManager(); chatManager = new ChatsManager(); fileManager = new FileManager(); //myAccount = new MyAccount(); //loading the default avatar image defaultAvatar = new Image("resources/defaultAvatar.png", 100, 120, true, true); showContacts();/*from www . ja v a 2 s . c o m*/ showAccountInfo(); addContactListener(); addFileRecieverListener(); addMessageListener(); showConversations(); addRosterListener(); addConversationListener(); addCallListener(); addMessageLimiter(); setUp(); }
From source file:org.sociotech.unui.javafx.engine2d.AbstractWorld.java
protected synchronized void addImage(String imageName, int width, int height) { m_imageResourceManager.put(imageName, new Image( Resources.getResource("images/" + imageName).toExternalForm(), width, height, true, true)); }