public Optional<String> toImageBlock(Image image) { if (!current.currentPath().isPresent()) asciiDocController.saveDoc(); Path currentPath = current.currentPath().map(Path::getParent).get(); IOHelper.createDirectories(currentPath.resolve("images")); List<String> buffer = new LinkedList<>(); DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(asciiDocController.getClipboardImageFilePattern()); Path path = Paths.get(dateTimeFormatter.format(LocalDateTime.now())); Path targetImage = currentPath.resolve("images").resolve(path.getFileName()); try { BufferedImage fromFXImage = SwingFXUtils.fromFXImage(image, null); ImageIO.write(fromFXImage, "png", targetImage.toFile()); } catch (Exception e) { logger.error("Problem occured while saving clipboard image {}", targetImage); } buffer.add(String.format("image::images/%s[]", path.getFileName())); if (buffer.size() > 0) return Optional.of(String.join("\n", buffer)); return Optional.empty(); }
public static BufferedImage getScreenshot(WebView browser) { if (browser != null) { WritableImage returnimage = browser.snapshot(new SnapshotParameters(), null); return SwingFXUtils.fromFXImage(returnimage, null); } return null; }
public static BufferedImage fromNode(Node node) { final WritableImage jfx = node.snapshot(null, null); final BufferedImage img = new BufferedImage((int) jfx.getWidth(), (int) jfx.getHeight(), BufferedImage.TYPE_INT_ARGB); SwingFXUtils.fromFXImage(jfx, img); return img; }
public static void setImageView(ImageView iv) { imageView = iv; angle = imageView.getRotate(); imageView.setRotate(0); image = SwingFXUtils.toFXImage( SwingFXUtils.fromFXImage(imageView.snapshot(null, null), null), null); }
private void saveImage() { try { // save ImageIO.write( SwingFXUtils.fromFXImage(imgPattern, null), "png", new File("pattern_" + width + "x" + height + ".png")); } catch (IOException ex) { System.out.println("Error saving image"); } }
/** * Saves a snapshot of an image to the users directory * * @param image the image to be saved * @param user the user to save the image to */ public static void SaveProfilePicture(Image image, User user) { String userDir = new File(Persistent.getProfileFilePath(user.getUserId())).getParent(); File file = new File(userDir + "/profile.png"); try { ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", file); } catch (IOException e) { // file path doesn't exist // System.out.println("Couldn't save picture. filePath not found"); } }
public static void saveCanvas(Canvas canvas, String name, String path) { int width = (int) canvas.getWidth(); int height = (int) canvas.getHeight(); WritableImage image = new WritableImage(width, height); canvas.snapshot(new SnapshotParameters(), image); File file = new File(name); try { ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", file); } catch (Exception e) { e.printStackTrace(); } }
@Override public void initialize(URL arg0, ResourceBundle arg1) { days.bind(viewModel.daysProperty()); targetLineSeries.dataProperty().bind(viewModel.targetLineDataProperty()); loggedHoursSeries.dataProperty().bind(viewModel.loggedHoursDataProperty()); burndownSeries.dataProperty().bind(viewModel.burndownDataProperty()); burndownChart.getData().addAll(targetLineSeries, loggedHoursSeries, burndownSeries); burndownChart.getXAxis().setAutoRanging(true); // style burndownChart.setLegendVisible(false); burndownChart.setAnimated(false); yAxis.setMinorTickVisible(false); exportHyperlink.setOnAction( event -> { burndownChart.snapshot( snapshotResult -> { WritableImage image = snapshotResult.getImage(); // https://community.oracle.com/thread/2450090?tstart=0 final FileChooser fileChooser = new FileChooser(); fileChooser .getExtensionFilters() .addAll( new FileChooser.ExtensionFilter("PNG Files", "*.png"), new FileChooser.ExtensionFilter("All Files", "*")); String organisationFilename = viewModel.organisationProperty().get().getSaveLocation().getName(); fileChooser.setInitialFileName( organisationFilename.substring(0, organisationFilename.lastIndexOf('.')) + ".png"); File file = fileChooser.showSaveDialog(burndownChart.getScene().getWindow()); try { if (file != null) { ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", file); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }, null, null); }); }
private void export() { FileChooser chooser = new FileChooser(); chooser .getExtensionFilters() .add( new FileChooser.ExtensionFilter( "Image file (png, jpg, gif)", "*.png", "*.jpg", "*.gif")); File file = chooser.showSaveDialog(Cyclist.cyclistStage); if (file != null) { WritableImage image = _chart.snapshot(new SnapshotParameters(), null); try { ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", file); } catch (IOException e) { log.error("Error writing image to file: " + e.getMessage()); } } }
@FXML public void saveAsPng() { WritableImage image = GraphicPane.snapshot(new SnapshotParameters(), null); FileChooser fileChooser = new FileChooser(); // Set extension filter FileChooser.ExtensionFilter extFilterPNG = new FileChooser.ExtensionFilter("PNG files (*.png)", "*.PNG"); fileChooser.getExtensionFilters().add(extFilterPNG); // TODO: probably use a file chooser here File fileF = fileChooser.showSaveDialog(this.mainApp.getPrimaryStage()); File file = new File(fileF.getAbsolutePath() + ".png"); try { ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", file); } catch (IOException e) { // TODO: handle exception here } }
public static int[][] convertImageTo2DIntArray(Image image, int width, int height) { int[][] returnArray = new int[height][width]; // Obtain PixelReader PixelReader pixelReader = image.getPixelReader(); int xSegmentLength = divideAByBThenRoundDown(image.getWidth(), width); int ySegmentLength = divideAByBThenRoundDown(image.getHeight(), height); BufferedImage bufferedImage = SwingFXUtils.fromFXImage(image, null); for (int row = 0; row < height; row++) { for (int column = 0; column < width; column++) { BufferedImage tempBufferedImage = bufferedImage.getSubimage( xSegmentLength * column, ySegmentLength * row, xSegmentLength, ySegmentLength); Color averageColor = AverageColorFinder.findAverageColorFromImage( SwingFXUtils.toFXImage(tempBufferedImage, null)); int argb = ((int) (averageColor.getOpacity() * 255) << 24) | ((int) (averageColor.getRed() * 255) << 16) | ((int) (averageColor.getGreen() * 255) << 8) | ((int) (averageColor.getBlue() * 255)); returnArray[row][column] = argb; } } return returnArray; }
private void createScreenShotButton() { screenShotButton = new Button(FontAwesome.ICON_CAMERA); screenShotButton.setFont(Font.font("FontAwesome", 14)); screenShotButton.setTooltip(new Tooltip("Take Screen Shot.")); // screenShotButton.disableProperty().bind(webEngine.getLoadWorker().runningProperty()); screenShotButton.setOnAction( observable -> { WritableImage image = masterPane.snapshot(null, null); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss'.png'"); FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Save Screen Shot..."); fileChooser.setInitialFileName(simpleDateFormat.format(Date.from(Instant.now()))); File imageFile = fileChooser.showSaveDialog(null); if (imageFile != null) { try { ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", imageFile); } catch (IOException e) { e.printStackTrace(); } } }); }
private static Image getImage() { BufferedImage image = SwingFXUtils.fromFXImage(imageView.snapshot(null, null), null); return SwingFXUtils.toFXImage(image, null); }