Bloom class is a part of JavaFX. Bloom is a high-level effect that makes brighter portions of the input image appear to glow, based on a configurable threshold. Bloom class inherits Effect class.
Constructors of the class:
- Bloom(): Creates a new Bloom Object .
- Bloom(double t): Creates a new Bloom effect with a specified threshold.
Commonly Used Methods:
| Method | Explanation |
|---|---|
| getInput() | Gets the value of the property input |
| getThreshold() | Returns the value of threshold |
| setInput(Effect v) | Sets the value of the property input |
| setThreshold(double v) | Sets the threshold value of the effect |
Below programs illustrate the use of Bloom class:
- Java program to import an image and add bloom effect to it: In this program a FileInputStream is created and an image is taken as input from a file. Image named image is created using the input from the file input stream. From the image, an image view object is created and it is added to the VBox.The VBox is then added to the scene and the scene is added to the stage. A Bloom effect is created with a specified level passed as parameters and the effect is set to the image view using setEffect() function.
// Java program to import an image// and add bloom effect to itimportjavafx.application.Application;importjavafx.scene.Scene;importjavafx.scene.control.*;importjavafx.scene.layout.*;importjavafx.stage.Stage;importjavafx.scene.image.*;importjavafx.scene.effect.*;importjava.io.*;importjavafx.event.ActionEvent;importjavafx.event.EventHandler;importjavafx.scene.Group;publicclassbloom_1extendsApplication {// launch the applicationpublicvoidstart(Stage stage)throwsException{// set title for the stagestage.setTitle("Bloom Example");// create a input streamFileInputStream input =newFileInputStream("D:\\GFG.png");// create a imageImage image =newImage(input);// create a image ViewImageView imageview =newImageView(image);// create a bloom effectBloom bloom =newBloom(0.9);// set effectimageview.setEffect(bloom);// create a VBoxVBox vbox =newVBox(imageview);// create a sceneScene scene =newScene(vbox,200,200);// set the scenestage.setScene(scene);stage.show();}// Main Methodpublicstaticvoidmain(String args[]){// launch the applicationlaunch(args);}}Input Image:
Output:
- Java program to import an image and set bloom effect to it, the Threshold value of the bloom effect can be controlled using a button: In this program an FileInputStream is created and an image is taken as input from a file. Image named image is created using the input from the file input stream. From the image, an image view object is created and it is added to the VBox.The VBox is then added to the scene and the scene is added to the stage. A Bloom effect is created with a specified level passed as parameters and the effect is set to the image view using setEffect() function. A Button named button is created which is used to increase the bloom of the image. The button is also added to the VBox. The bloom of the image is increased using the setThreshold() function. The events related to button is handled using EventHandler.
// Java program to import an image and// set bloom effect to it. The Threshold// value of the bloom effect can be// controlled using the buttonimportjavafx.application.Application;importjavafx.scene.Scene;importjavafx.scene.control.*;importjavafx.scene.layout.*;importjavafx.stage.Stage;importjavafx.scene.image.*;importjavafx.scene.effect.*;importjava.io.*;importjavafx.event.ActionEvent;importjavafx.event.EventHandler;importjavafx.scene.Group;publicclassbloom_2extendsApplication {doublelevel =0.1;// launch the applicationpublicvoidstart(Stage stage)throwsException{// set title for the stagestage.setTitle("Bloom Example");// create a input streamFileInputStream input =newFileInputStream("D:\\GFG.png");// create a imageImage image =newImage(input);// create a image ViewImageView imageview =newImageView(image);// create a bloom effectBloom bloom =newBloom(level);// create a buttonButton button =newButton("bloom");// action eventEventHandler<ActionEvent> event =newEventHandler<ActionEvent>() {publicvoidhandle(ActionEvent e){// increase the levellevel +=0.1;if(level >1)level =0.0;// set Level for bloombloom.setThreshold(level);}};// set on action of buttonbutton.setOnAction(event);// set effectimageview.setEffect(bloom);// create a VBoxVBox vbox =newVBox(imageview, button);// create a sceneScene scene =newScene(vbox,200,200);// set the scenestage.setScene(scene);stage.show();}// Main Methodpublicstaticvoidmain(String args[]){// launch the applicationlaunch(args);}}Output:
Note: The above programs might not run in an online IDE. Please use an offline compiler.
Reference: https://docs.oracle.com/javase/8/javafx/api/javafx/scene/effect/Bloom.html
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.




