JavaFx | GaussianBlur Class
GaussianBlur is a part of JavaFX. GaussianBlur is an implementation of a blur effect using a Gaussian convolution kernel, with a configurable radius.
Constructors of the class:
- GaussianBlur(): Creates an new object of GaussianBlur.
- GaussianBlur(double r): Creates a new Object of GaussianBlur with a specified radius.
Commonly Used Methods:
| Method | Explanation |
|---|---|
| getRadius() | Return the value of the property radius. |
| getInput() | Return the value of the property input. |
| setInput(Effect val) | Sets the value of the property input. |
| setRadius(double val) | Sets the value of the property radius. |
Below programs illustrate the use of GaussianBlur class:
- Java program to import an image and add GaussianBlur 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 GaussianBlur 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 Gaussian Blur 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;publicclassgaussian_blur_1extendsApplication {// launch the applicationpublicvoidstart(Stage stage)throwsException{// set title for the stagestage.setTitle("GussianBlur 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 gaussian blur effectGaussianBlur gaussian_blur =newGaussianBlur();// set effectimageview.setEffect(gaussian_blur);// 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);}}chevron_rightfilter_noneInput Image:
-
Java program to import an image and add GaussianBlur effect to it with a specified radius: 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 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 GaussianBlur effect is created with a specified level passed as parameters and the effect is set to the image view using setEffect() function. The radius of the GaussianBlur is specified using the setRadius() function.
// Java program to import an image and// add Gaussian Blur effect to it with// a specified radiusimportjavafx.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;publicclassgaussian_blur_2extendsApplication {// launch the applicationpublicvoidstart(Stage stage)throwsException{// set title for the stagestage.setTitle("GaussianBlur 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 gaussian blur effectGaussianBlur gaussian_blur =newGaussianBlur();// set radius for gaussian blurgaussian_blur.setRadius(20.0f);// set effectimageview.setEffect(gaussian_blur);// 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);}}chevron_rightfilter_noneInput Image:
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/GaussianBlur.html






