Glow Effect

Just like the Bloom Effect, the Glow Effect also makes the given input image to glow. This effect makes the pixels of the input much brighter.

The class named Glow of the package javafx.scene.effect represents the glow effect. This class contains two properties namely −

  • input − This property is of the type Effect and it represents an input to the glow effect.
  • level − This property is of the type double; it represents intensity of the glow. The range of the level value is 0.0 to 1.0.

Example

The following program is an example demonstrating the Glow Effect of JavaFX. In here, we are embedding the following image (Tutorialspoint Logo) in JavaFX scene using Image and ImageView classes. This will be done at the position 100, 70 and with fit height and fit width 200 and 400 respectively.

To this image, we are applying the Glow Effect with the level value 0.9. Save this code in a file with the name GlowEffectExample.java.

importjavafx.application.Application;importjavafx.scene.Group;importjavafx.scene.Scene;importjavafx.scene.effect.Glow;importjavafx.scene.image.Image;importjavafx.scene.image.ImageView;importjavafx.stage.Stage;publicclassGlowEffectExampleextendsApplication{@Overridepublicvoidstart(Stage stage){//Creating an image Image image =newImage("http://www.tutorialspoint.com/green/images/logo.png");//Setting the image view ImageView imageView =newImageView(image);//setting the fit width of the image view 
      imageView.setFitWidth(200);//Setting the preserve ratio of the image view 
      imageView.setPreserveRatio(true);//Instantiating the Glow class Glow glow =newGlow();//setting level of the glow effect 
      glow.setLevel(0.9);//Applying bloom effect to text 
      imageView.setEffect(glow);//Creating a Group object  Group root =newGroup(imageView);//Creating a scene object Scene scene =newScene(root,600,300);//Setting title to the Stage 
      stage.setTitle("Sample Application");//Adding scene to the stage 
      stage.setScene(scene);//Displaying the contents of the stage 
      stage.show();}publicstaticvoidmain(String args[]){launch(args);}}

Compile and execute the saved java file from the command prompt using the following commands.

javac --module-path %PATH_TO_FX%--add-modules javafx.controls GlowEffectExample.java 
java --module-path %PATH_TO_FX%--add-modules javafx.controls GlowEffectExample

Output

On executing, the above program generates a JavaFX window as shown below.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *