The bloom effect makes portions of an image appear to glow, based on a configurable threshold.
Bloom class provides following constructors to define Bloom instance.
public Bloom()
public Bloom(double threshold)
‘threshold’ specifies the threshold value for the bloom effect. The threshold varies from 0.0 to 1.0. By default, the threshold is set to 0.3 (threshold is the luminosity value of the pixel). If threshold is set to 0, then all the pixels will glow, if the threshold is set to 1, no pixel glows.
Example
Bloom bloom1 = new Bloom();
bloom1.setThreshold(0.0f);
text1.setFill(Color.GREEN);
Example fxml
<Text fx:id = "text1" text="JavaFX"
style="-fx-font-weight: bold; -fx-font-size: 50; -fx-font-family: Verdana; -fx-font-style: italic"
stroke="darkblue" strokeWidth="2"
underline="true"
fill="yellow"
effect="$bloomEffect1">
<Bloom fx:id="bloomEffect1" threshold="0.1f" />
</Text>
Find the below working application.
bloomEffect.fxml
<?import javafx.scene.*?>
<?import javafx.scene.shape.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.effect.*?>
<StackPane xmlns:fx="http://javafx.com/fxml" fx:controller="com.sample.app.effects.controller.BloomEffectController">
<Rectangle fx:id="rectangle1" arcHeight="30" arcWidth="30" fill="green"
width="300" height="50" smooth="true" stroke="black" strokeWidth="5" />
<Text fx:id = "text1" text="JavaFX"
style="-fx-font-weight: bold; -fx-font-size: 50; -fx-font-family: Verdana; -fx-font-style: italic"
stroke="darkblue" strokeWidth="2"
underline="true"
fill="yellow"
effect="$bloomEffect1">
<Bloom fx:id="bloomEffect1" threshold="0.1f" />
</Text>
</StackPane>
BloomEffectController.java
package com.sample.app.effects.controller;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Text;
public class BloomEffectController implements Initializable {
@FXML
private Rectangle rectangle1;
@FXML
private Text text1;
@Override
public void initialize(URL location, ResourceBundle resources) {
}
}
BloomEffectDemo.java
package com.sample.app.effects;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
public class BloomEffectDemo extends Application {
private static final String FXML_FILE = "/bloomEffect.fxml";
private static final String STAGE_TITLE = "Bloom Effect";
public static void main(String args[]) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
Parent root = (Parent) FXMLLoader.load(this.getClass().getResource(FXML_FILE));
Scene scene = new Scene(root, 600, 400, Color.LIGHTGRAY);
primaryStage.setTitle(STAGE_TITLE);
primaryStage.setScene(scene);
primaryStage.show();
}
}
Output
Previous Next Home
No comments:
Post a Comment