List of usage examples for javafx.scene.paint Color TRANSPARENT
Color TRANSPARENT
To view the source code for javafx.scene.paint Color TRANSPARENT.
Click Source Link
From source file:net.rptools.tokentool.util.ImageUtil.java
private static Image clipImageWithMask(Image imageSource, Image imageMask) { int imageWidth = (int) imageMask.getWidth(); int imageHeight = (int) imageMask.getHeight(); WritableImage outputImage = new WritableImage(imageWidth, imageHeight); PixelReader pixelReader_Mask = imageMask.getPixelReader(); PixelReader pixelReader_Source = imageSource.getPixelReader(); PixelWriter pixelWriter = outputImage.getPixelWriter(); for (int readY = 0; readY < imageHeight; readY++) { for (int readX = 0; readX < imageWidth; readX++) { Color pixelColor = pixelReader_Mask.getColor(readX, readY); if (pixelColor.equals(Color.TRANSPARENT)) pixelWriter.setColor(readX, readY, pixelReader_Source.getColor(readX, readY)); }//from www. j a v a 2 s .c o m } return outputImage; }
From source file:net.rptools.tokentool.util.ImageUtil.java
private static Image autoCropImage(Image imageSource) { ImageView croppedImageView = new ImageView(imageSource); PixelReader pixelReader = imageSource.getPixelReader(); int imageWidth = (int) imageSource.getWidth(); int imageHeight = (int) imageSource.getHeight(); int minX = imageWidth, minY = imageHeight, maxX = 0, maxY = 0; // Find the first and last pixels that are not transparent to create a bounding viewport for (int readY = 0; readY < imageHeight; readY++) { for (int readX = 0; readX < imageWidth; readX++) { Color pixelColor = pixelReader.getColor(readX, readY); if (!pixelColor.equals(Color.TRANSPARENT)) { if (readX < minX) minX = readX;/*from ww w . j av a 2 s. c o m*/ if (readX > maxX) maxX = readX; if (readY < minY) minY = readY; if (readY > maxY) maxY = readY; } } } if (maxX - minX <= 0 || maxY - minY <= 0) return new WritableImage(1, 1); // Create a viewport to clip the image using snapshot Rectangle2D viewPort = new Rectangle2D(minX, minY, maxX - minX, maxY - minY); SnapshotParameters parameter = new SnapshotParameters(); parameter.setViewport(viewPort); parameter.setFill(Color.TRANSPARENT); return croppedImageView.snapshot(parameter, null); }
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.jav a 2 s .c o 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:io.bitsquare.gui.main.overlays.Overlay.java
public void display() { if (owner == null) owner = MainView.getRootContainer(); if (owner != null) { Scene rootScene = owner.getScene(); if (rootScene != null) { Scene scene = new Scene(gridPane); scene.getStylesheets().setAll(rootScene.getStylesheets()); scene.setFill(Color.TRANSPARENT); setupKeyHandler(scene);/* w w w . j a v a2 s. c o m*/ stage = new Stage(); stage.setScene(scene); Window window = rootScene.getWindow(); setModality(); stage.initStyle(StageStyle.TRANSPARENT); stage.show(); layout(); addEffectToBackground(); // On Linux the owner stage does not move the child stage as it does on Mac // So we need to apply centerPopup. Further with fast movements the handler loses // the latest position, with a delay it fixes that. // Also on Mac sometimes the popups are positioned outside of the main app, so keep it for all OS positionListener = (observable, oldValue, newValue) -> { if (stage != null) { layout(); if (centerTime != null) centerTime.stop(); centerTime = UserThread.runAfter(this::layout, 3); } }; window.xProperty().addListener(positionListener); window.yProperty().addListener(positionListener); window.widthProperty().addListener(positionListener); animateDisplay(); } } }
From source file:eu.mihosoft.vrl.fxscad.MainController.java
@FXML private void onExportAsPngFile(ActionEvent e) { if (csgObject == null) { Action response = Dialogs.create().title("Error").message("Cannot export PNG. There is no geometry :(") .lightweight().showError(); return;//w w w .j ava 2 s. c o m } FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Export PNG File"); fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Image files (*.png)", "*.png")); File f = fileChooser.showSaveDialog(null); if (f == null) { return; } String fName = f.getAbsolutePath(); if (!fName.toLowerCase().endsWith(".png")) { fName += ".png"; } int snWidth = 1024; int snHeight = 1024; double realWidth = viewGroup.getBoundsInLocal().getWidth(); double realHeight = viewGroup.getBoundsInLocal().getHeight(); double scaleX = snWidth / realWidth; double scaleY = snHeight / realHeight; double scale = Math.min(scaleX, scaleY); PerspectiveCamera snCam = new PerspectiveCamera(false); snCam.setTranslateZ(-200); SnapshotParameters snapshotParameters = new SnapshotParameters(); snapshotParameters.setTransform(new Scale(scale, scale)); snapshotParameters.setCamera(snCam); snapshotParameters.setDepthBuffer(true); snapshotParameters.setFill(Color.TRANSPARENT); WritableImage snapshot = new WritableImage(snWidth, (int) (realHeight * scale)); viewGroup.snapshot(snapshotParameters, snapshot); try { ImageIO.write(SwingFXUtils.fromFXImage(snapshot, null), "png", new File(fName)); } catch (IOException ex) { Logger.getLogger(MainController.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:net.rptools.tokentool.controller.TokenTool_Controller.java
@FXML void initialize() { // Note: A Pane is added to the compositeTokenPane so the ScrollPane doesn't consume the mouse events assert fileManageOverlaysMenu != null : "fx:id=\"fileManageOverlaysMenu\" was not injected: check your FXML file 'TokenTool.fxml'."; assert fileSaveAsMenu != null : "fx:id=\"fileSaveAsMenu\" was not injected: check your FXML file 'TokenTool.fxml'."; assert fileExitMenu != null : "fx:id=\"fileExitMenu\" was not injected: check your FXML file 'TokenTool.fxml'."; assert editCaptureScreenMenu != null : "fx:id=\"editCaptureScreenMenu\" was not injected: check your FXML file 'TokenTool.fxml'."; assert editCopyImageMenu != null : "fx:id=\"editCopyImageMenu\" was not injected: check your FXML file 'TokenTool.fxml'."; assert editPasteImageMenu != null : "fx:id=\"editPasteImageMenu\" was not injected: check your FXML file 'TokenTool.fxml'."; assert helpAboutMenu != null : "fx:id=\"helpAboutMenu\" was not injected: check your FXML file 'TokenTool.fxml'."; assert saveOptionsPane != null : "fx:id=\"saveOptionsPane\" was not injected: check your FXML file 'TokenTool.fxml'."; assert overlayOptionsPane != null : "fx:id=\"overlayOptionsPane\" was not injected: check your FXML file 'TokenTool.fxml'."; assert backgroundOptionsPane != null : "fx:id=\"backgroundOptionsPane\" was not injected: check your FXML file 'TokenTool.fxml'."; assert zoomOptionsPane != null : "fx:id=\"zoomOptionsPane\" was not injected: check your FXML file 'TokenTool.fxml'."; assert compositeTokenPane != null : "fx:id=\"compositeTokenPane\" was not injected: check your FXML file 'TokenTool.fxml'."; assert tokenPreviewPane != null : "fx:id=\"tokenPreviewPane\" was not injected: check your FXML file 'TokenTool.fxml'."; assert portraitScrollPane != null : "fx:id=\"portraitScrollPane\" was not injected: check your FXML file 'TokenTool.fxml'."; assert compositeGroup != null : "fx:id=\"compositeGroup\" was not injected: check your FXML file 'TokenTool.fxml'."; assert overlayTreeView != null : "fx:id=\"overlayTreeview\" was not injected: check your FXML file 'TokenTool.fxml'."; assert portraitImageView != null : "fx:id=\"portraitImageView\" was not injected: check your FXML file 'TokenTool.fxml'."; assert maskImageView != null : "fx:id=\"maskImageView\" was not injected: check your FXML file 'TokenTool.fxml'."; assert overlayImageView != null : "fx:id=\"overlayImageView\" was not injected: check your FXML file 'TokenTool.fxml'."; assert tokenImageView != null : "fx:id=\"tokenImageView\" was not injected: check your FXML file 'TokenTool.fxml'."; assert useFileNumberingCheckbox != null : "fx:id=\"useFileNumberingCheckbox\" was not injected: check your FXML file 'TokenTool.fxml'."; assert overlayUseAsBaseCheckbox != null : "fx:id=\"overlayUseAsBaseCheckbox\" was not injected: check your FXML file 'TokenTool.fxml'."; assert clipPortraitCheckbox != null : "fx:id=\"clipPortraitCheckbox\" was not injected: check your FXML file 'TokenTool.fxml'."; assert fileNameTextField != null : "fx:id=\"fileNameTextField\" was not injected: check your FXML file 'TokenTool.fxml'."; assert fileNameSuffixLabel != null : "fx:id=\"fileNameSuffixLabel\" was not injected: check your FXML file 'TokenTool.fxml'."; assert fileNameSuffixTextField != null : "fx:id=\"fileNameSuffixTextField\" was not injected: check your FXML file 'TokenTool.fxml'."; assert overlayNameLabel != null : "fx:id=\"overlayNameLabel\" was not injected: check your FXML file 'TokenTool.fxml'."; assert backgroundColorPicker != null : "fx:id=\"backgroundColorPicker\" was not injected: check your FXML file 'TokenTool.fxml'."; assert overlayAspectToggleButton != null : "fx:id=\"overlayAspectToggleButton\" was not injected: check your FXML file 'TokenTool.fxml'."; assert portraitTransparencySlider != null : "fx:id=\"portraitTransparencySlider\" was not injected: check your FXML file 'TokenTool.fxml'."; assert portraitBlurSlider != null : "fx:id=\"portraitBlurSlider\" was not injected: check your FXML file 'TokenTool.fxml'."; assert portraitGlowSlider != null : "fx:id=\"portraitGlowSlider\" was not injected: check your FXML file 'TokenTool.fxml'."; assert overlayTransparencySlider != null : "fx:id=\"overlayTransparencySlider\" was not injected: check your FXML file 'TokenTool.fxml'."; assert overlayWidthSpinner != null : "fx:id=\"overlayWidthSpinner\" was not injected: check your FXML file 'TokenTool.fxml'."; assert overlayHeightSpinner != null : "fx:id=\"overlayHeightSpinner\" was not injected: check your FXML file 'TokenTool.fxml'."; assert overlayTreeProgressBar != null : "fx:id=\"overlayTreeProgressIndicator\" was not injected: check your FXML file 'ManageOverlays.fxml'."; executorService = Executors.newCachedThreadPool(runable -> { loadOverlaysThread = Executors.defaultThreadFactory().newThread(runable); loadOverlaysThread.setDaemon(true); return loadOverlaysThread; });//from w ww . j a v a 2 s .co m overlayTreeView.setShowRoot(false); overlayTreeView.getSelectionModel().selectedItemProperty().addListener( (observable, oldValue, newValue) -> updateCompositImageView((TreeItem<Path>) newValue)); addPseudoClassToLeafs(overlayTreeView); // Bind color picker to compositeTokenPane background fill backgroundColorPicker.setValue(Color.TRANSPARENT); ObjectProperty<Background> background = compositeTokenPane.backgroundProperty(); background.bind(Bindings.createObjectBinding(() -> { BackgroundFill fill = new BackgroundFill(backgroundColorPicker.getValue(), CornerRadii.EMPTY, Insets.EMPTY); return new Background(fill); }, backgroundColorPicker.valueProperty())); // Bind transparency slider to portraitImageView opacity portraitTransparencySlider.valueProperty().addListener(new ChangeListener<Number>() { public void changed(ObservableValue<? extends Number> ov, Number old_val, Number new_val) { portraitImageView.setOpacity(new_val.doubleValue()); updateTokenPreviewImageView(); } }); // // Restrict text field to valid filename characters // Pattern validDoubleText = Pattern.compile("[^a-zA-Z0-9\\\\._ \\\\/`~!@#$%\\\\^&\\\\(\\\\)\\\\-\\\\=\\\\+\\\\[\\\\]\\\\{\\\\}',\\\\\\\\:]"); // Pattern validText = Pattern.compile("[^a-zA-Z0-9 ]"); // TextFormatter<> textFormatter = new TextFormatter<>( // change -> { // String newText = change.getControlNewText(); // if (validText.matcher(newText).matches()) { // return change; // } else // return null; // }); // UnaryOperator<TextFormatter.Change> filter = new UnaryOperator<TextFormatter.Change>() { // @Override // public TextFormatter.Change apply(TextFormatter.Change t) { // String validText = "[^a-zA-Z0-9]"; // // if (t.isReplaced()) // if (t.getText().matches(validText)) // t.setText(t.getControlText().substring(t.getRangeStart(), t.getRangeEnd())); // // if (t.isAdded()) { // if (t.getText().matches(validText)) { // return null; // } // } // // return t; // } // }; UnaryOperator<Change> filter = change -> { String text = change.getText(); if (text.matches(AppConstants.VALID_FILE_NAME_PATTERN)) { return change; } else { change.setText(FileSaveUtil.cleanFileName(text)); ; return change; } // // return null; }; TextFormatter<String> textFormatter = new TextFormatter<>(filter); fileNameTextField.setTextFormatter(textFormatter); // Effects GaussianBlur gaussianBlur = new GaussianBlur(0); Glow glow = new Glow(0); gaussianBlur.setInput(glow); // Bind blur slider to portraitImageView opacity portraitBlurSlider.valueProperty().addListener(new ChangeListener<Number>() { public void changed(ObservableValue<? extends Number> ov, Number old_val, Number new_val) { gaussianBlur.setRadius(new_val.doubleValue()); portraitImageView.setEffect(gaussianBlur); updateTokenPreviewImageView(); } }); // Bind glow slider to portraitImageView opacity portraitGlowSlider.valueProperty().addListener(new ChangeListener<Number>() { public void changed(ObservableValue<? extends Number> ov, Number old_val, Number new_val) { glow.setLevel(new_val.doubleValue()); portraitImageView.setEffect(gaussianBlur); updateTokenPreviewImageView(); } }); // Bind transparency slider to overlayImageView opacity overlayTransparencySlider.valueProperty().addListener(new ChangeListener<Number>() { public void changed(ObservableValue<? extends Number> ov, Number old_val, Number new_val) { overlayImageView.setOpacity(new_val.doubleValue()); updateTokenPreviewImageView(); } }); // Bind width/height spinners to overlay width/height overlayWidthSpinner.getValueFactory().valueProperty() .bindBidirectional(overlayHeightSpinner.getValueFactory().valueProperty()); overlayWidthSpinner.valueProperty().addListener( (observable, oldValue, newValue) -> overlayWidthSpinner_onTextChanged(oldValue, newValue)); overlayHeightSpinner.valueProperty().addListener( (observable, oldValue, newValue) -> overlayHeightSpinner_onTextChanged(oldValue, newValue)); }
From source file:net.rptools.tokentool.util.ImageUtil.java
private static Image processMagenta(Image inputImage, int colorThreshold, boolean overlayWanted) { int imageWidth = (int) inputImage.getWidth(); int imageHeight = (int) inputImage.getHeight(); WritableImage outputImage = new WritableImage(imageWidth, imageHeight); PixelReader pixelReader = inputImage.getPixelReader(); PixelWriter pixelWriter = outputImage.getPixelWriter(); for (int readY = 0; readY < imageHeight; readY++) { for (int readX = 0; readX < imageWidth; readX++) { Color pixelColor = pixelReader.getColor(readX, readY); if (isMagenta(pixelColor, COLOR_THRESHOLD) == overlayWanted) pixelWriter.setColor(readX, readY, Color.TRANSPARENT); else/* w w w . j av a 2s .c om*/ pixelWriter.setColor(readX, readY, pixelColor); } } return outputImage; }
From source file:be.makercafe.apps.makerbench.editors.JFXMillEditor.java
private void handleExportAsPngFile(ActionEvent e) { if (millObject == null) { Alert alert = new Alert(AlertType.ERROR); alert.setTitle("Oeps an error occured"); alert.setHeaderText("Cannot export PNG. There is no geometry !"); alert.setContentText("Please verify that your code generates a valid CSG object."); alert.showAndWait();/* w w w . jav a 2 s. c om*/ return; } FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Export PNG File"); fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Image files (*.png)", "*.png")); File f = fileChooser.showSaveDialog(null); if (f == null) { return; } String fName = f.getAbsolutePath(); if (!fName.toLowerCase().endsWith(".png")) { fName += ".png"; } int snWidth = 1024; int snHeight = 1024; double realWidth = viewGroup.getBoundsInLocal().getWidth(); double realHeight = viewGroup.getBoundsInLocal().getHeight(); double scaleX = snWidth / realWidth; double scaleY = snHeight / realHeight; double scale = Math.min(scaleX, scaleY); PerspectiveCamera snCam = new PerspectiveCamera(false); snCam.setTranslateZ(-200); SnapshotParameters snapshotParameters = new SnapshotParameters(); snapshotParameters.setTransform(new Scale(scale, scale)); snapshotParameters.setCamera(snCam); snapshotParameters.setDepthBuffer(true); snapshotParameters.setFill(Color.TRANSPARENT); WritableImage snapshot = new WritableImage(snWidth, (int) (realHeight * scale)); viewGroup.snapshot(snapshotParameters, snapshot); try { ImageIO.write(SwingFXUtils.fromFXImage(snapshot, null), "png", new File(fName)); } catch (IOException ex) { Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex); Alert alert = new Alert(AlertType.ERROR); alert.setTitle("Oeps an error occured"); alert.setHeaderText("Cannot export PNG. There went something wrong writing the file."); alert.setContentText( "Please verify that your file is not read only, is not locked by other user or program, you have enough diskspace."); alert.showAndWait(); } }
From source file:be.makercafe.apps.makerbench.editors.GCodeEditor.java
private void handleExportAsPngFile(ActionEvent e) { if (csgObject == null) { Alert alert = new Alert(AlertType.ERROR); alert.setTitle("Oeps an error occured"); alert.setHeaderText("Cannot export PNG. There is no geometry !"); alert.setContentText("Please verify that your code generates a valid CSG object."); alert.showAndWait();//from w w w .j av a 2 s.com return; } FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Export PNG File"); fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Image files (*.png)", "*.png")); File f = fileChooser.showSaveDialog(null); if (f == null) { return; } String fName = f.getAbsolutePath(); if (!fName.toLowerCase().endsWith(".png")) { fName += ".png"; } int snWidth = 1024; int snHeight = 1024; double realWidth = viewGroup.getBoundsInLocal().getWidth(); double realHeight = viewGroup.getBoundsInLocal().getHeight(); double scaleX = snWidth / realWidth; double scaleY = snHeight / realHeight; double scale = Math.min(scaleX, scaleY); PerspectiveCamera snCam = new PerspectiveCamera(false); snCam.setTranslateZ(-200); SnapshotParameters snapshotParameters = new SnapshotParameters(); snapshotParameters.setTransform(new Scale(scale, scale)); snapshotParameters.setCamera(snCam); snapshotParameters.setDepthBuffer(true); snapshotParameters.setFill(Color.TRANSPARENT); WritableImage snapshot = new WritableImage(snWidth, (int) (realHeight * scale)); viewGroup.snapshot(snapshotParameters, snapshot); try { ImageIO.write(SwingFXUtils.fromFXImage(snapshot, null), "png", new File(fName)); } catch (IOException ex) { Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex); Alert alert = new Alert(AlertType.ERROR); alert.setTitle("Oeps an error occured"); alert.setHeaderText("Cannot export PNG. There went something wrong writing the file."); alert.setContentText( "Please verify that your file is not read only, is not locked by other user or program, you have enough diskspace."); alert.showAndWait(); } }
From source file:net.rptools.tokentool.controller.TokenTool_Controller.java
@FXML void removeBackgroundButton_onAction(ActionEvent event) { backgroundColorPicker.setValue(Color.TRANSPARENT); updateTokenPreviewImageView(); }