javafx.scene.SnapshotParameters Java Examples
The following examples show how to use
javafx.scene.SnapshotParameters.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FXPaintUtils.java From gef with Eclipse Public License 2.0 | 7 votes |
/** * Creates a rectangular {@link Image} to visualize the given {@link Paint}. * * @param width * The width of the resulting {@link Image}. * @param height * The height of the resulting {@link Image}. * @param paint * The {@link Paint} to use for filling the {@link Image}. * @return The resulting (filled) {@link Image}. */ public static ImageData getPaintImageData(int width, int height, Paint paint) { // use JavaFX canvas to render a rectangle with the given paint Canvas canvas = new Canvas(width, height); GraphicsContext graphicsContext = canvas.getGraphicsContext2D(); graphicsContext.setFill(paint); graphicsContext.fillRect(0, 0, width, height); graphicsContext.setStroke(Color.BLACK); graphicsContext.strokeRect(0, 0, width, height); // handle transparent color separately (we want to differentiate it from // transparent fill) if (paint instanceof Color && ((Color) paint).getOpacity() == 0) { // draw a red line from bottom-left to top-right to indicate a // transparent fill color graphicsContext.setStroke(Color.RED); graphicsContext.strokeLine(0, height - 1, width, 1); } WritableImage snapshot = canvas.snapshot(new SnapshotParameters(), null); return SWTFXUtils.fromFXImage(snapshot, null); }
Example #2
Source File: Items.java From logbook-kai with MIT License | 6 votes |
/** * 装備アイコンを返します * * @param type 装備 * @param slot スロット背景 * @return 装備アイコン * @throws IllegalStateException このメソッドがJavaFXアプリケーション・スレッド以外のスレッドで呼び出された場合 */ private static Image itemIcon(int type, boolean slot) { Image image = optimizeItemIcon(type); if (slot) { return CACHE.get("slotItemIcon#" + type, key -> { double width = image.getWidth(); double height = image.getHeight(); Canvas canvas = new Canvas(width, height); GraphicsContext gc = canvas.getGraphicsContext2D(); gc.setFill(Color.rgb(44, 58, 59)); gc.fillOval(2, 2, width - 2, height - 2); gc.drawImage(image, 0, 0); SnapshotParameters sp = new SnapshotParameters(); sp.setFill(Color.TRANSPARENT); return canvas.snapshot(sp, null); }); } return image; }
Example #3
Source File: LivePanel.java From Quelea with GNU General Public License v3.0 | 6 votes |
/** * Get a preview image of the web view or move it to the main panel if it's * not visible. * * @return a screenshot image of the web view */ private Image geWebPreviewImage() { DisplayCanvas canvas = QueleaApp.get().getProjectionWindow().getCanvas(); if (QueleaApp.get().getProjectionWindow().isShowing() && isContentShowing()) { Double d = canvas.getBoundsInLocal().getHeight(); int h = d.intValue(); Double d2 = canvas.getBoundsInLocal().getWidth(); ; int w = d2.intValue(); webPreviewImage = new WritableImage(w, h); SnapshotParameters params = new SnapshotParameters(); params.setFill(Color.TRANSPARENT); canvas.snapshot(params, webPreviewImage); BufferedImage bi = SwingFXUtils.fromFXImage((WritableImage) webPreviewImage, null); SwingFXUtils.toFXImage(bi, webPreviewImage); WebView wv = getWebPanel().removeWebView(); if (wv != null && !canvas.getChildren().contains(wv)) { canvas.getChildren().add(wv); } return webPreviewImage; } else { getWebPanel().addWebView((WebDisplayable) getDisplayable()); return new Image("file:icons/web preview.png"); } }
Example #4
Source File: TileImage.java From mcaselector with MIT License | 6 votes |
static void createMarkedChunksImage(Tile tile, int zoomLevel) { WritableImage wImage = new WritableImage(Tile.SIZE / zoomLevel, Tile.SIZE / zoomLevel); Canvas canvas = new Canvas(Tile.SIZE / (float) zoomLevel, Tile.SIZE / (float) zoomLevel); GraphicsContext ctx = canvas.getGraphicsContext2D(); ctx.setFill(Config.getChunkSelectionColor().makeJavaFXColor()); for (Point2i markedChunk : tile.markedChunks) { Point2i regionChunk = markedChunk.mod(Tile.SIZE_IN_CHUNKS); if (regionChunk.getX() < 0) { regionChunk.setX(regionChunk.getX() + Tile.SIZE_IN_CHUNKS); } if (regionChunk.getY() < 0) { regionChunk.setY(regionChunk.getY() + Tile.SIZE_IN_CHUNKS); } ctx.fillRect(regionChunk.getX() * Tile.CHUNK_SIZE / (float) zoomLevel, regionChunk.getY() * Tile.CHUNK_SIZE / (float) zoomLevel, Tile.CHUNK_SIZE / (float) zoomLevel, Tile.CHUNK_SIZE / (float) zoomLevel); } SnapshotParameters params = new SnapshotParameters(); params.setFill(Color.TRANSPARENT.makeJavaFXColor()); canvas.snapshot(params, wImage); tile.markedChunksImage = wImage; }
Example #5
Source File: EpidemicReportsChartController.java From MyBox with Apache License 2.0 | 6 votes |
protected File snapWidth(SnapshotParameters snapPara, double scale, int width, Region chart) { try { Bounds bounds = chart.getLayoutBounds(); int imageWidth = (int) Math.round(bounds.getWidth() * scale); int imageHeight = (int) Math.round(bounds.getHeight() * scale); Image snap = chart.snapshot(snapPara, new WritableImage(imageWidth, imageHeight)); BufferedImage bufferedImage = SwingFXUtils.fromFXImage(snap, null); if (bufferedImage.getWidth() > width) { bufferedImage = ImageManufacture.scaleImageWidthKeep(bufferedImage, snapWidth); } File tmpfile = FileTools.getTempFile(".png"); ImageFileWriters.writeImageFile(bufferedImage, "png", tmpfile.getAbsolutePath()); return tmpfile; } catch (Exception e) { logger.debug(e.toString()); return null; } }
Example #6
Source File: SVGDocumentGenerator.java From latexdraw with GNU General Public License v3.0 | 6 votes |
/** * Creates a thumbnail from the given selection in the given file. * @param templateFile The file of the future thumbnail. * @param selection The set of shapes composing the template. */ private void createTemplateThumbnail(final File templateFile, final javafx.scene.Group selection) { final Bounds bounds = selection.getBoundsInParent(); final double scale = 70d / Math.max(bounds.getWidth(), bounds.getHeight()); final WritableImage img = new WritableImage((int) (bounds.getWidth() * scale), (int) (bounds.getHeight() * scale)); final SnapshotParameters snapshotParameters = new SnapshotParameters(); snapshotParameters.setFill(Color.WHITE); snapshotParameters.setTransform(new Scale(scale, scale)); selection.snapshot(snapshotParameters, img); final BufferedImage bufferedImage = SwingFXUtils.fromFXImage(img, null); try { ImageIO.write(bufferedImage, "png", templateFile); //NON-NLS }catch(final IOException ex) { BadaboomCollector.INSTANCE.add(ex); } bufferedImage.flush(); }
Example #7
Source File: Tools.java From logbook-kai with MIT License | 6 votes |
/** * ノードの内容をPNGファイルとして出力します * * @param node ノード * @param title タイトル及びファイル名 * @param own 親ウインドウ */ public static void storeSnapshot(Node node, String title, Window own) { try { FileChooser chooser = new FileChooser(); chooser.setTitle(title + "の保存"); chooser.setInitialFileName(title + ".png"); chooser.getExtensionFilters().addAll( new ExtensionFilter("PNG Files", "*.png")); File f = chooser.showSaveDialog(own); if (f != null) { SnapshotParameters sp = new SnapshotParameters(); sp.setFill(Color.WHITESMOKE); WritableImage image = node.snapshot(sp, null); try (OutputStream out = Files.newOutputStream(f.toPath())) { ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", out); } } } catch (Exception e) { alert(AlertType.WARNING, "画像ファイルに保存出来ませんでした", "指定された場所へ画像ファイルを書き込みできませんでした", e, own); } }
Example #8
Source File: HelperTest.java From latexdraw with GNU General Public License v3.0 | 6 votes |
default <T extends Node> void assertNotEqualsSnapshot(final T node, final CmdFXVoid toExecBetweenSnap) { Bounds bounds = node.getBoundsInLocal(); final SnapshotParameters params = new SnapshotParameters(); final WritableImage oracle = new WritableImage((int) bounds.getWidth(), (int) bounds.getHeight()); Platform.runLater(() -> node.snapshot(params, oracle)); WaitForAsyncUtils.waitForFxEvents(); if(toExecBetweenSnap != null) { toExecBetweenSnap.execute(); } bounds = node.getBoundsInLocal(); final WritableImage observ = new WritableImage((int) bounds.getWidth(), (int) bounds.getHeight()); Platform.runLater(() -> node.snapshot(params, observ)); WaitForAsyncUtils.waitForFxEvents(); assertNotEquals("The two snapshots do not differ.", 100d, computeSnapshotSimilarity(oracle, observ), 0.001); }
Example #9
Source File: ShipImage.java From logbook-kai with MIT License | 6 votes |
/** * ゲージを作成する * @param width ゲージの幅 * @param height ゲージの高さ * @param per 割合 * @param colorFunc 色 * @param cache キャッシュ * @return ゲージのImage */ private static Image createGauge(double width, double height, double per, Function<Double, Color> colorFunc, ReferenceCache<Double, Image> cache) { double size = (int) Math.max((Math.max(width, height) * per), 0); return cache.get(size, key -> { Canvas canvas = new Canvas(width, height); GraphicsContext gc = canvas.getGraphicsContext2D(); gc.setFill(Color.TRANSPARENT.interpolate(Color.WHITE, 0.6)); if (width < height) { gc.fillRect(0, 0, width, height - size); } else { gc.fillRect(size, 0, width - size, height); } gc.setFill(colorFunc.apply(size / Math.max(width, height))); if (width < height) { gc.fillRect(0, height - size, width, size); } else { gc.fillRect(0, 0, size, height); } SnapshotParameters sp = new SnapshotParameters(); sp.setFill(Color.TRANSPARENT); return canvas.snapshot(sp, null); }); }
Example #10
Source File: FxmlControl.java From MyBox with Apache License 2.0 | 6 votes |
public static Image snap(Node node) { try { final Bounds bounds = node.getLayoutBounds(); double scale = dpiScale(); int imageWidth = (int) Math.round(bounds.getWidth() * scale); int imageHeight = (int) Math.round(bounds.getHeight() * scale); final SnapshotParameters snapPara = new SnapshotParameters(); snapPara.setFill(Color.TRANSPARENT); snapPara.setTransform(javafx.scene.transform.Transform.scale(scale, scale)); WritableImage snapshot = new WritableImage(imageWidth, imageHeight); snapshot = node.snapshot(snapPara, snapshot); return snapshot; } catch (Exception e) { logger.debug(e.toString()); return null; } }
Example #11
Source File: ResourcesMutator.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
public void createScreenshotCallback_old(String id, int x, int y, int w, int h) { Platform.runLater(()->{ //System.out.println("in screenshot callback id "+id); //System.out.println(imageProcessors); if (imageProcessors.containsKey(id)) { double ratio = 1.0; //this.targetDensity = Display.DENSITY_VERY_HIGH; SnapshotParameters params = new SnapshotParameters(); //params.setTransform(Transform.scale(ratio, ratio)); params.setFill(Color.TRANSPARENT); WritableImage wi = web.snapshot(params, null); BufferedImage img = SwingFXUtils.fromFXImage(wi, null); img = img.getSubimage((int)(x*ratio), (int)(y*ratio), (int)(w*ratio), (int)(h*ratio)); imageProcessors.get(id).process(img); } web.getEngine().executeScript("window.captureScreenshots()"); }); }
Example #12
Source File: TweetsToTori.java From TweetwallFX with MIT License | 6 votes |
private BufferedImage snapshotTweet(final Parent tweetContainer) throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); // render the chart in an offscreen scene (scene is used to allow css processing) and snapshot it to an image. // the snapshot is done in runlater as it must occur on the javafx application thread. final SimpleObjectProperty<BufferedImage> imageProperty = new SimpleObjectProperty<>(); Platform.runLater(() -> { Scene snapshotScene = new Scene(tweetContainer); final SnapshotParameters params = new SnapshotParameters(); params.setFill(Color.WHITESMOKE); tweetContainer.snapshot(result -> { imageProperty.set(SwingFXUtils.fromFXImage(result.getImage(), null)); latch.countDown(); return null; }, params, null); }); latch.await(); return imageProperty.get(); }
Example #13
Source File: DigitFactory.java From metastone with GNU General Public License v2.0 | 6 votes |
public static void saveAllDigits() { Stage stage = new Stage(StageStyle.TRANSPARENT); DigitTemplate root = new DigitTemplate(); Scene scene = new Scene(root); stage.setScene(scene); stage.show(); SnapshotParameters snapshotParams = new SnapshotParameters(); snapshotParams.setFill(Color.TRANSPARENT); root.digit.setText("-"); for (int i = 0; i <= 10; i++) { WritableImage image = root.digit.snapshot(snapshotParams, null); File file = new File("src/" + IconFactory.RESOURCE_PATH + "/img/common/digits/" + root.digit.getText() + ".png"); try { ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", file); } catch (IOException e) { e.printStackTrace(); } root.digit.setText("" + i); } stage.close(); }
Example #14
Source File: ViewUtils.java From ApkToolPlus with Apache License 2.0 | 6 votes |
/** * 把一个Node导出为png图片 * * @param node 节点 * @param saveFile 图片文件 * @param width 宽 * @param height 高 * @return 是否导出成功 */ public static boolean node2Png(Node node, File saveFile, double width, double height) { SnapshotParameters parameters = new SnapshotParameters(); // 背景透明 parameters.setFill(Color.TRANSPARENT); WritableImage image = node.snapshot(parameters, null); // 重置图片大小 ImageView imageView = new ImageView(image); imageView.setFitWidth(width); imageView.setFitHeight(height); WritableImage exportImage = imageView.snapshot(parameters, null); try { return ImageIO.write(SwingFXUtils.fromFXImage(exportImage, null), "png", saveFile); } catch (IOException e) { e.printStackTrace(); } return false; }
Example #15
Source File: TargetSlide.java From ShootOFF with GNU General Public License v3.0 | 6 votes |
@Override public void newTarget(File targetFile) { final Optional<TargetComponents> targetComponents = TargetIO.loadTarget(targetFile); if (!targetComponents.isPresent()) { logger.error("Notified of a new target that cannot be loaded: {}", targetFile.getAbsolutePath()); return; } final Image targetImage = targetComponents.get().getTargetGroup().snapshot(new SnapshotParameters(), null); final ImageView targetImageView = new ImageView(targetImage); targetImageView.setFitWidth(60); targetImageView.setFitHeight(60); targetImageView.setPreserveRatio(true); targetImageView.setSmooth(true); final String targetPath = targetFile.getPath(); final String targetName = targetPath .substring(targetPath.lastIndexOf(File.separator) + 1, targetPath.lastIndexOf('.')).replace("_", " "); itemPane.addButton(targetFile, targetName, Optional.of(targetImageView), Optional.empty()); }
Example #16
Source File: ExtendedAnimatedFlowContainer.java From tools-ocr with GNU Lesser General Public License v3.0 | 6 votes |
private void updatePlaceholder(Node newView) { if (view.getWidth() > 0 && view.getHeight() > 0) { SnapshotParameters parameters = new SnapshotParameters(); parameters.setFill(Color.TRANSPARENT); Image placeholderImage = view.snapshot(parameters, new WritableImage((int) view.getWidth(), (int) view.getHeight())); placeholder.setImage(placeholderImage); placeholder.setFitWidth(placeholderImage.getWidth()); placeholder.setFitHeight(placeholderImage.getHeight()); } else { placeholder.setImage(null); } placeholder.setVisible(true); placeholder.setOpacity(1.0); view.getChildren().setAll(placeholder, newView); placeholder.toFront(); }
Example #17
Source File: ExtendedAnimatedFlowContainer.java From JFoenix with Apache License 2.0 | 6 votes |
private void updatePlaceholder(Node newView) { if (view.getWidth() > 0 && view.getHeight() > 0) { SnapshotParameters parameters = new SnapshotParameters(); parameters.setFill(Color.TRANSPARENT); Image placeholderImage = view.snapshot(parameters, new WritableImage((int) view.getWidth(), (int) view.getHeight())); placeholder.setImage(placeholderImage); placeholder.setFitWidth(placeholderImage.getWidth()); placeholder.setFitHeight(placeholderImage.getHeight()); } else { placeholder.setImage(null); } placeholder.setVisible(true); placeholder.setOpacity(1.0); view.getChildren().setAll(placeholder, newView); placeholder.toFront(); }
Example #18
Source File: ImageUtil.java From Augendiagnose with GNU General Public License v2.0 | 5 votes |
/** * Retrieve an overlay image. * * @param overlayType * The overlay type. * @param side * The side of the eye. * @param color * The overlay color. * * @return The overlay image. */ private static Image getOverlayImage(final int overlayType, final RightLeft side, final Color color) { URL imageUrl = ClassLoader.getSystemResource("overlay/" + getOverlayFileName(overlayType, side)); Image image = new Image(imageUrl.toExternalForm()); Canvas canvas = new Canvas(OVERLAY_SIZE, OVERLAY_SIZE); Color colorNoAlpha = new Color(color.getRed(), color.getGreen(), color.getBlue(), 1); Blend effect = new Blend( BlendMode.SRC_ATOP, null, new ColorInput( 0, 0, OVERLAY_SIZE, OVERLAY_SIZE, colorNoAlpha)); // Type 2 is not changed in color. if (overlayType != 2) { canvas.getGraphicsContext2D().setEffect(effect); } canvas.getGraphicsContext2D().setGlobalAlpha(color.getOpacity()); canvas.getGraphicsContext2D().drawImage(image, 0, 0, OVERLAY_SIZE, OVERLAY_SIZE); SnapshotParameters parameters = new SnapshotParameters(); parameters.setFill(Color.TRANSPARENT); return canvas.snapshot(parameters, null); }
Example #19
Source File: ResourcesMutator.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
public void createScreenshotCallback(String id, int x, int y, int w, int h) { Platform.runLater(()->{ //System.out.println("in screenshot callback id "+id); //System.out.println(imageProcessors); if (imageProcessors.containsKey(id)) { double ratio = 1.0; //this.targetDensity = Display.DENSITY_VERY_HIGH; SnapshotParameters params = new SnapshotParameters(); //params.setTransform(Transform.scale(ratio, ratio)); params.setFill(Color.TRANSPARENT); try { WebviewSnapshotter snapper = new WebviewSnapshotter(web, params); snapper.setBounds(x, y, w, h); snapper.snapshot(()-> { BufferedImage img = snapper.getImage(); imageProcessors.get(id).process(img); Platform.runLater(()-> { web.getEngine().executeScript("window.captureScreenshots()"); }); }); } catch (Throwable t) { Log.p("Failed to create snapshot for UIID "+id+": "+t.getMessage()); Log.e(t); Platform.runLater(()-> { web.getEngine().executeScript("window.captureScreenshots()"); }); } } else { Platform.runLater(()-> { web.getEngine().executeScript("window.captureScreenshots()"); }); } }); }
Example #20
Source File: MainLayoutController.java From javafx-TKMapEditor with GNU General Public License v3.0 | 5 votes |
@FXML public void onExportToImageAction(ActionEvent e) { File file = exportFileChooser.showSaveDialog(null); if (file != null) { WritableImage image = mapCanvas.snapshot(new SnapshotParameters(), null); try { ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", file); AlertDialog.showAlertDialog("保存成功!"); } catch (IOException ex) { AlertDialog.showAlertDialog("保存失败:" + ex.getMessage()); } } }
Example #21
Source File: Ships.java From logbook-kai with MIT License | 5 votes |
/** * キャラクターの画像を取得します(装飾無し、バックグラウンドでのロード) * * @param chara キャラクター * @return 艦娘の画像 * @throws IllegalStateException このメソッドがJavaFXアプリケーション・スレッド以外のスレッドで呼び出された場合 */ public static Image getBackgroundLoading(Chara chara) throws IllegalStateException { Image img = ShipImage.getBackgroundLoading(chara); if (img != null) { return img; } Canvas canvas = new Canvas(160, 40); SnapshotParameters sp = new SnapshotParameters(); sp.setFill(Color.TRANSPARENT); return canvas.snapshot(sp, null); }
Example #22
Source File: ShipImage.java From logbook-kai with MIT License | 5 votes |
/** * 補給ゲージ(燃料・弾薬)を取得します * * @param ship 艦娘 * @return 補給ゲージ */ static Image getSupplyGauge(Ship ship) { Canvas canvas = new Canvas(36, 12); GraphicsContext gc = canvas.getGraphicsContext2D(); Optional<ShipMst> mstOpt = Ships.shipMst(ship); if (mstOpt.isPresent()) { double width = canvas.getWidth(); ShipMst mst = mstOpt.get(); double fuelPer = (double) ship.getFuel() / (double) mst.getFuelMax(); double ammoPer = (double) ship.getBull() / (double) mst.getBullMax(); gc.setFill(Color.GRAY); gc.fillRect(0, 3, width, 2); gc.setFill(Color.GRAY); gc.fillRect(0, 10, width, 2); Color fuelColor = fuelPer >= 0.5D ? Color.GREEN : fuelPer >= 0.4D ? Color.ORANGE : Color.RED; Color ammoColor = ammoPer >= 0.5D ? Color.SADDLEBROWN : ammoPer >= 0.4D ? Color.ORANGE : Color.RED; gc.setFill(fuelColor); gc.fillRect(0, 0, width * fuelPer, 4); gc.setFill(ammoColor); gc.fillRect(0, 7, width * ammoPer, 4); } SnapshotParameters sp = new SnapshotParameters(); sp.setFill(Color.TRANSPARENT); return canvas.snapshot(sp, null); }
Example #23
Source File: Patterns.java From FXyzLib with GNU General Public License v3.0 | 5 votes |
public Image createPattern(CarbonPatterns cp, boolean save) { ImagePattern pattern; switch (cp) { case DARK_CARBON: pattern = createCarbonPattern(); break; case LIGHT_CARBON: pattern = createLightCarbonPattern(); break; case CARBON_KEVLAR: pattern = createCarbonKevlarPattern(); break; default: pattern = createCarbonPattern(); break; } Rectangle rectangle = new Rectangle(width, height); if (pattern != null) { rectangle.setFill(pattern); } rectangle.setStrokeWidth(0); imgPattern = rectangle.snapshot(new SnapshotParameters(), null); if (save) { saveImage(); } return imgPattern; }
Example #24
Source File: ResourcesMutator.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
BufferedImage createHtmlScreenshot(WebView web, String html) { final boolean[] complete = new boolean[1]; final Object lock = new Object(); final BufferedImage[] img = new BufferedImage[1]; Runnable webpageLoadedCallback = () -> { SnapshotParameters params = new SnapshotParameters(); params.setFill(Color.TRANSPARENT); WritableImage wi = web.snapshot(params, null); img[0] = SwingFXUtils.fromFXImage(wi, null); complete[0] = true; synchronized(lock) { lock.notify(); } }; Platform.runLater(()->{ web.getEngine().loadContent(html); }); while (!complete[0]) { synchronized(lock) { try { lock.wait(); } catch (InterruptedException ex) { Logger.getLogger(CN1CSSCompiler.class.getName()).log(Level.SEVERE, null, ex); } } } return img[0]; }
Example #25
Source File: ViewSingleShape.java From latexdraw with GNU General Public License v3.0 | 5 votes |
private Paint getHatchingsFillingPaint(final FillingStyle style) { final Bounds bounds = border.getBoundsInParent(); if(bounds.getWidth() <= 0d || bounds.getHeight() <= 0d) { return null; } final Group hatchings = new Group(); final double hAngle = model.getHatchingsAngle(); hatchings.getChildren().add(new Rectangle(bounds.getWidth(), bounds.getHeight(), style.isFilled() ? model.getFillingCol().toJFX() : null)); final double angle = hAngle > 0d ? hAngle - Math.PI / 2d : hAngle + Math.PI / 2d; switch(style) { case VLINES, VLINES_PLAIN -> computeHatchings(hatchings, hAngle, bounds.getWidth(), bounds.getHeight()); case HLINES, HLINES_PLAIN -> computeHatchings(hatchings, angle, bounds.getWidth(), bounds.getHeight()); case CLINES, CLINES_PLAIN -> { computeHatchings(hatchings, hAngle, bounds.getWidth(), bounds.getHeight()); computeHatchings(hatchings, angle, bounds.getWidth(), bounds.getHeight()); } } final WritableImage image = new WritableImage((int) bounds.getWidth(), (int) bounds.getHeight()); hatchings.snapshot(new SnapshotParameters(), image); return new ImagePattern(image, 0, 0, 1, 1, true); }
Example #26
Source File: RepositoriesPanelSkin.java From phoenicis with GNU Lesser General Public License v3.0 | 5 votes |
/** * Creates an {@link Image} object visualizing a dragged repository location * * @param repositoryLocation The dragged repository location * @return An {@link Image} object visualizing a dragged repository location */ private Image createPreviewImage(RepositoryLocation<? extends Repository> repositoryLocation) { final Text text = new Text(repositoryLocation.toDisplayString()); // force the layout to be able to create a snapshot new Scene(new Group(text)); final SnapshotParameters snapshotParameters = new SnapshotParameters(); snapshotParameters.setFill(Color.TRANSPARENT); return text.snapshot(snapshotParameters, null); }
Example #27
Source File: JFXDialog.java From JFoenix with Apache License 2.0 | 5 votes |
private void showDialog() { if (dialogContainer == null) { throw new RuntimeException("ERROR: JFXDialog container is not set!"); } if (isCacheContainer()) { tempContent = new ArrayList<>(dialogContainer.getChildren()); SnapshotParameters snapShotparams = new SnapshotParameters(); snapShotparams.setFill(Color.TRANSPARENT); WritableImage temp = dialogContainer.snapshot(snapShotparams, new WritableImage((int) dialogContainer.getWidth(), (int) dialogContainer.getHeight())); ImageView tempImage = new ImageView(temp); tempImage.setCache(true); tempImage.setCacheHint(CacheHint.SPEED); dialogContainer.getChildren().setAll(tempImage, this); } else { //prevent error if opening an already opened dialog dialogContainer.getChildren().remove(this); tempContent = null; dialogContainer.getChildren().add(this); } if (animation != null) { animation.play(); } else { setVisible(true); setOpacity(1); Event.fireEvent(JFXDialog.this, new JFXDialogEvent(JFXDialogEvent.OPENED)); } }
Example #28
Source File: Export.java From latexdraw with GNU General Public License v3.0 | 5 votes |
/** * @return A writable image that contains given views (not null). */ private @NotNull BufferedImage createRenderedImage() { final Group views = canvas.getViews(); final Bounds bounds = views.getBoundsInParent(); final double scale = 3d; final WritableImage img = new WritableImage((int) (bounds.getWidth() * scale), (int) (bounds.getHeight() * scale)); final SnapshotParameters snapshotParameters = new SnapshotParameters(); snapshotParameters.setFill(Color.WHITE); snapshotParameters.setTransform(new Scale(scale, scale)); views.snapshot(snapshotParameters, img); return SwingFXUtils.fromFXImage(img, null); }
Example #29
Source File: Items.java From logbook-kai with MIT License | 5 votes |
/** * 装備アイコンを調節します * * @param p 装備アイコンへのパス * @return 装備アイコン */ private static Image optimizeItemIcon(int type) { Path dir = Paths.get(AppConfig.get().getResourcesDir()); Path p = dir.resolve(Paths.get("common", "common_icon_weapon/common_icon_weapon_id_" + type + ".png")); return CACHE.get(p.toUri().toString(), (url, status) -> { Image image = new Image(url); if (image.isError()) { status.setDoCache(false); return defaultItemIcon(); } double width = image.getWidth(); double height = image.getHeight(); if (width != ITEM_ICON_SIZE) { double x = (int) ((ITEM_ICON_SIZE - width) / 2); double y = (int) ((ITEM_ICON_SIZE - height) / 2); Canvas canvas = new Canvas(ITEM_ICON_SIZE, ITEM_ICON_SIZE); GraphicsContext gc = canvas.getGraphicsContext2D(); gc.drawImage(image, x, y); SnapshotParameters sp = new SnapshotParameters(); sp.setFill(Color.TRANSPARENT); return canvas.snapshot(sp, null); } return image; }); }
Example #30
Source File: CachePolicy.java From JFoenix with Apache License 2.0 | 5 votes |
@Override public void cache(Pane node) { if (!cache.containsKey(node)) { SnapshotParameters snapShotparams = new SnapshotParameters(); snapShotparams.setFill(Color.TRANSPARENT); WritableImage temp = node.snapshot(snapShotparams, new WritableImage((int) node.getLayoutBounds().getWidth(), (int) node.getLayoutBounds().getHeight())); ImageView tempImage = new ImageView(temp); tempImage.setCache(true); tempImage.setCacheHint(CacheHint.SPEED); cache.put(node, new ArrayList<>(node.getChildren())); node.getChildren().setAll(tempImage); } }