Table of contents
1.
Introduction
1.1.
Constructors
1.2.
Properties
1.3.
Usage
2.
Implementation
3.
Frequently Asked Questions
3.1.
What is the SepiaTone effect?
3.2.
What are constructors in JFX?
3.3.
Is JavaFX different from Java?
4.
Conclusion
Last Updated: Mar 27, 2024
Medium

JavaFX SepiaTone

Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

JavaFX includes the SepiaTone class. The SepiaTone class is used to provide a sepia tone effect to a picture, similar to that of an antique photograph. SepiaTone Effect basically changes the tone of the image to a reddish brown color.

SepiaTone JavaFX Example 

Source: Adobe

The class javafx.scene.effect.SepiaTone in JavaFX represents the SepiaTone effect. To generate an appropriate impact, we simply need to instantiate this class.

Constructors

The SepiaTone class contains two constructors

  1. public Sepiatone(): creates a new instance of SepiaTone class.
     
  2. public Sepiatone(double level): Creates a new instance with a specified level value.

Properties

The table below describes the SepiaTone class properties as well as the setter methods.

Properties of SepiaTone

Usage

This program serves as an example of the SepiaTone Effect in JavaFX. In this case, we are using the Image and ImageView classes to display an image of the Coding Ninjas logo in a JavaFX scene.

The Sepia Tone Effect has been applied to this image. Put this code in a file called SepiaToneEffectExample.java.

Implementation

import javafx.application.Application; 
import javafx.scene.Scene; 
import javafx.scene.Group; 
import javafx.scene.effect.SepiaTone; 
import javafx.scene.image.ImageView; 
import javafx.scene.image.Image; 
import javafx.stage.Stage;  


public class SepiaToneEffectExample extends Application { 
   @Override 
   public void start(Stage stage) {       
      //import the image
      Image image = new Image("D://CodingNinjas.png"); 
       
      //Setting the image view 
      ImageView imageView = new ImageView(image); 
      
      //Setting the position of the image  
      imageView.setX(150); 
      imageView.setY(0);
      
      //Instantiate the SepiaTone class 
      SepiaTone sepiaTone = new SepiaTone(); 
      
      //Set the level of the effect 
      sepiaTone.setLevel(0.8); 
      
      //Applying SepiaTone effect to the image 
      imageView.setEffect(sepiaTone);      
         
      //Creating a Group and scene object  
      Group root = new Group(imageView);
      Scene scene = new Scene(root, 600, 300);  
      
      //Setting title to the Stage 
      stage.setTitle("Sepia tone effect example"); 
         
      //Adding scene to the stage 
      stage.setScene(scene); 
         
      //Displaying the contents
      stage.show();         
   } 
   public static void main(String args[]){ 
      launch(args); 
   } 
}
You can also try this code with Online Java Compiler
Run Code


Execution

To execute the above program. You can follow the given steps:

  1. Open the terminal in the same folder where you have saved your source code.
     
  2. Enter the below code and hit enter.
    javac --module-path path/to/your/javaFx/modules --add-modules javafx.fxml,javafx.controls filename.java
     
  3. After you hit enter a new file will automatically be generated namely filename.class
     
  4. Now, enter the below command and hit enter to execute the above program.
    java --module-path path/to/your/javaFx/modules --add-modules javafx.fxml,javafx.controls filename.java
     
  5. You have successfully executed the JavaFX program.


Output

Output

Frequently Asked Questions

What is the SepiaTone effect?

The Sepia Tone effect adds a rich brown color tint to your photos, giving them a warm, almost antique feel.
 

What are constructors in JFX?

A constructor in JFX is a block of code that is similar to a method. It is called when a new instance of the class is created.
 

Is JavaFX different from Java?

JavaFX is actually a different language than Java (similar, but different syntax), but it runs on a JVM and can use Java classes. It is mainly developed for "RIA" (rich Internet applications) across a variety of devices.

Conclusion

In this article, we have extensively discussed the SepiaTone Class present inside JavaFX. We have seen different constructors to initialize the SepiaTone effect. Also, we have seen various methods available inside the class along with the implementation.

If you think this blog has helped you enhance your knowledge about JavaFx path transition and if you would like to learn more, check out our articles JavaFXJavaFX Rotate TransitionJavaFX Introduction, and many more in our Library.

Refer to our Guided Path on Coding Ninjas Studio to upskill yourself in Data Structures and AlgorithmsCompetitive ProgrammingJavaScriptSystem Design, and many more! If you want to test your competency in coding, you may check out the mock test series and participate in the contests hosted on Coding Ninjas Studio! But suppose you have just started your learning process and are looking for questions asked by tech giants like Amazon, Microsoft, Uber, etc. In that case, you must look at the problemsinterview experiences, and interview bundle for placement preparations.

Do upvote our blogs if you find them helpful and engaging!

Happy Learning!

Live masterclass