×

JavaFX Image Input

In the JavaFX application, in order to apply various image input effect, we use the ImageInput class. It has the ability to fill the specified shape with a given image input effect. All methods needed for this purpose are present in the javafx.scene.effect.ImageInput class.

Properties and corresponding methods to create Image Input Effect :

1. x

This property is of double type. It is used to represent the x top left coordinate of the shape and the setX( double xvalue ) method is used to set it.

2. y

This property is of double type. It is used to represent the y top left coordinate of the shape and the setY( double yvalue) method is used to set it.

3. source

This property is of image type. It is used to represent the url of the specified image and the setImage( Image img ) method is used to set it.

JavaFX Effect – Image Input

Example:

import javafx.application.Application;  
import javafx.scene.Group;  
import javafx.scene.Scene;  
import javafx.scene.effect.ImageInput;
import javafx.scene.image.Image;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;  


public class EffectUI extends Application {  


    @Override  
    public void start(Stage stage) throws Exception 
    { 
    
      Image img = new Image("https://icons.iconarchive.com/icons/custom-icon-design/pretty-office-4/256/home-icon.png");  
        ImageInput imginput = new ImageInput();  
        Rectangle rect = new Rectangle();  
        imginput.setSource(img);  
        imginput.setX(20);  
        imginput.setY(70);  
        Group root = new Group();  
        rect.setEffect(imginput);  
        root.getChildren().add(rect);  
         Scene scene = new Scene(root,700,450);  
         stage.setScene(scene);  
        stage.setTitle("JavaFx Image Input Effect example");  
         stage.show();  
     }
      
    public static void main(String[] args) {  
        launch(args);  
    }  
}

Output:

In order to create the image Input Effect in JavaFX, we have to import all the required libraries such as javafx.application.Application, javafx.scene.Group, javafx.scene.Scene, javafx.scene.effect.ColorInput, javafx.scene.paint.Color, javafx.scene.shape.Rectangle, javafx.scene.effect.ImageInput, javafx.scene.image.Image, javafx.stage.Stage.

Then we have created one class named EffectUI extending the Application class. Also, we have to override the start method to provide implementation details. This method creates an object of Stage as primaryStage. For the container to hold a rectangle filled with image input effect, a Group object is created which is then passed to the Scene class object.

The rectangle is created with the help of the constructor and Image input constructor is created, various properties are set using the setters, and the setEffect() method is used to set the image input effect on the rectangle.

The stage is prepared, the title is set and the show() method is called to display output. In order to run the application, the launch(args) method is called in the main() method. In output Frame like container is displayed with the title, " JavaFX Image Input Effect example". Also, it displays a rectangle with a home icon image input effect on it.

JavaFX Effect – Image Input

JavaFX Effect – Rectangles with and without Image Input Effect Example :

Example:

import javafx.application.Application;  
import javafx.scene.Group;  
import javafx.scene.Scene;  
import javafx.scene.effect.ImageInput;
import javafx.scene.image.Image;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Text;
import javafx.stage.Stage;  


public class EffectUI extends Application {  


    @Override  
    public void start(Stage stage) throws Exception 
    { 
    
      Image img = new Image("https://icons.iconarchive.com/icons/custom-icon-design/pretty-office-4/256/home-icon.png");  
        ImageInput imginput = new ImageInput();  
        Rectangle rect = new Rectangle();  
        Rectangle rect2 = new Rectangle();  
            rect2.setX(320);
            rect2.setY(90);;
        rect2.setHeight(240);  
          rect2.setWidth(240);  
          Text text1 = new Text();  
            Text text2 = new Text();  
            text1.setText("ImageInput Effect Applied");  
            text2.setText("ImageInput Effect Not Applied");  
            text1.setX(100);  
            text1.setY(350);  
            text2.setX(350);  
            text2.setY(350);  
            text1.setFill(Color.RED);  
            text2.setFill(Color.RED);  
            text1.setStroke(Color.BLACK);  
            text2.setStroke(Color.BLACK);  
            text1.setStrokeWidth(0.2);  
            text2.setStrokeWidth(0.2);  
       


        imginput.setSource(img);  
        imginput.setX(20);  
        imginput.setY(70);  
        Group root = new Group(rect,rect2,text1,text2);  
        rect.setEffect(imginput);  
        
         Scene scene = new Scene(root,700,450);  
         stage.setScene(scene);  
        stage.setTitle("JavaFx Image Input Effect example");  
         stage.show();  
     }
      
    public static void main(String[] args) {  
        launch(args);  
    }  
}

Output:

In order to create the rectangle with and without image Input Effect in JavaFX, we have to import all the required libraries such as javafx.application.Application, javafx.scene.Group, javafx.scene.Scene, javafx.scene.effect.ColorInput, javafx.scene.paint.Color, javafx.scene.shape.Rectangle, javafx.scene.effect.ImageInput, javafx.scene.image.Image, javafx.stage.Stage.

Then we have created one class named EffectUI extending the Application class. Also, we have to override the start method to provide implementation details. This method creates an object of Stage as primaryStage. For the container to hold a rectangle filled with and without image input effect, a Group object is created which is then passed to the Scene class object.

The rectangle is created with the help of the constructor and the Image input constructor is created, various properties are set using the setters and the setEffect() method is used to set the image input effect on one rectangle and other without effect.

The stage is prepared, the title is set and the show() method is called to display output. In order to run the application, the launch(args) method is called in the main() method. In output Frame like container is displayed with the title, " JavaFX Image Input Effect example”. Also, it displays a rectangle with and without a home icon image input effect on it.

JavaFX Effect – Image Input

Related Topics

JavaFX Fade Transition

In the JavaFX application, in order to generate the fade transition, we have to apply fade transition on any particular shape. It has the ability to show the fading colors...

4 minutes read.

JavaFX Pause Transition

In the JavaFX application, in order to generate the pause transition, we have to apply pause transition on any particular shape. It has the ability to take a particular pause...

4 minutes read.

JavaFX Reflection

In the JavaFX application, in order to apply various reflection effect, we use this class. It has the ability to create the reflection of the given object. This effect adds...

4 minutes read.

JavaFX Color Input

In the JavaFX application, in order to apply various color input effect, we use the ColorInput class. It has the ability to fill the specified shape with a given color...

4 minutes read.

JavaFX Line

In the JavaFX application, in order to draw a line, the Line class is used. The line allows us to join any two points with x and y coordinates in...

3 minutes read.

JavaFX Box

In the JavaFX application, in order to draw a Box, the Box class is used. The Box allows us to form 3D shape having rectangular faces. All methods needed for...

4 minutes read.

JavaFX Light Distant

In the JavaFX application, in order to apply various Light Distant effect from a single source, we use this class. It has the ability to apply light from a distant...

4 minutes read.

JavaFX Line Chart

In the JavaFX application, in order to create a Line Chart, LineChart class is used. The LineChart allows us to plot markers point according to the entities on number axes....

4 minutes read.

JavaFX Circle

In the JavaFX application, in order to draw a circle, the Circle class is used. The Circle allows us to join any points in the space. All methods needed for...

4 minutes read.

JavaFX Gradient Color

In the JavaFX application, in order to draw any shape, we are using classes present in the javafx.scene.shape package. We can fill the gradient colors in these shapes using the...

7 minutes read.

JavaFX TilePane

In the JavaFX application, in order to set TilePane as a layout, the TilePane class is used. The TilePane layout allows us to arrange the components in the same sized...

4 minutes read.

JavaFX PasswordField

In the JavaFX application, to get the user information and password as input from the user, a form is created using textfields and password fields which allows the user to...

4 minutes read.

JavaFX Color Adjust

In the JavaFX application, in order to apply various color adjust effect, we use ColorAdjust class. It has the ability to apply various color adjust effect such as hue, saturation,...

5 minutes read.

JavaFX Translation

In the JavaFX application, in order to apply various Translate effect, we use this class. It has the ability to Translate the given object according to the specified parameter. All...

4 minutes read.

JavaFX Architecture

JavaFX architecture consists of many built-in components such as JavaFX public API, Scene Graph, Quantum Toolkit, Prism, Glass windowing toolkit, web view, media engines. These components help to develop rich...

3 minutes read.

JavaFX Rotate Transition

In the JavaFX application, in order to generate the rotate transition, we have to apply rotation transition on any particular shape. It has the ability to rotate the shape along...

4 minutes read.

JavaFX Bar Chart

In the JavaFX application, in order to create Bar Chart, the BarChart class is used. The Bar Chart allows us to plot data along different bars to show the scales...

4 minutes read.

JavaFX Menu

In the JavaFX application, in order to create a menu, menu items, and menu bar, Menu, MenuItem, and MenuBar class is used. The menu allows us to choose options among...

4 minutes read.

JavaFX Light Point

In the JavaFX application, in order to apply various LightPoint effect from a single source, we use this class. It has the ability to apply light from a single source...

4 minutes read.

JavaFX GridPane

In the JavaFX application, in order to set Grid Pane as a layout, the GridPane class is used. The GridPane layout allows us to arrange the components in the form...

4 minutes read.