JavaFX | Bloom类

Bloom类是JavaFX的一部分。Bloom是一种高级效果,根据可配置的阈值,使输入图像的较亮部分看起来发光。Bloom类继承 效应

null

类的构造函数:

  1. 布鲁姆() :创建一个新的Bloom对象。
  2. 布鲁姆(双t) :创建具有指定阈值的新Bloom效果。

常用方法:

方法 解释
getInput() 获取属性输入的值
getThreshold() 返回阈值
设置输入(效果v) 设置属性输入的值
设置阈值(双v) 设置效果的阈值

以下程序说明了Bloom类的使用:

  1. 用于导入图像并向其添加bloom效果的Java程序: 在这个节目中 文件输入流类 创建并从文件中获取图像作为输入。图像名为 形象 使用文件输入流中的输入创建。从图片上看,一个 图像视图对象 创建并将其添加到 VBox 。然后将VBox添加到场景,并将场景添加到舞台。使用作为参数传递的指定级别创建Bloom效果,并使用 setEffect() 作用

    // Java program to import an image
    // and add bloom effect to it
    import javafx.application.Application;
    import javafx.scene.Scene;
    import javafx.scene.control.*;
    import javafx.scene.layout.*;
    import javafx.stage.Stage;
    import javafx.scene.image.*;
    import javafx.scene.effect.*;
    import java.io.*;
    import javafx.event.ActionEvent;
    import javafx.event.EventHandler;
    import javafx.scene.Group;
    public class bloom_1 extends Application {
    // launch the application
    public void start(Stage stage) throws Exception
    {
    // set title for the stage
    stage.setTitle( "Bloom Example" );
    // create a input stream
    FileInputStream input = new FileInputStream( "D:\GFG.png" );
    // create a image
    Image image = new Image(input);
    // create a image View
    ImageView imageview = new ImageView(image);
    // create a bloom effect
    Bloom bloom = new Bloom( 0.9 );
    // set effect
    imageview.setEffect(bloom);
    // create a VBox
    VBox vbox = new VBox(imageview);
    // create a scene
    Scene scene = new Scene(vbox, 200 , 200 );
    // set the scene
    stage.setScene(scene);
    stage.show();
    }
    // Main Method
    public static void main(String args[])
    {
    // launch the application
    launch(args);
    }
    }

    
    

    输入图像:

    图片[1]-JavaFX | Bloom类-yiteyi-C++库

    输出:

    图片[2]-JavaFX | Bloom类-yiteyi-C++库

  2. Java程序导入图像并为其设置bloom effect,可以使用按钮控制bloom effect的阈值: 在这个节目中 文件输入流类 创建并从文件中获取图像作为输入。图像名为 形象 使用文件输入流中的输入创建。从图片上看,一个 图像视图对象 创建并将其添加到 VBox 这个 VBox 然后被添加到场景中,场景被添加到舞台上。使用作为参数传递的指定级别创建Bloom效果,并使用 setEffect() 作用将创建一个名为Button的按钮,用于增加图像的亮度。该按钮也会添加到 VBox 。使用 setThreshold() 作用与按钮相关的事件使用 事件处理程序 .

    // Java program to import an image and
    // set bloom effect to it. The Threshold
    // value of the bloom effect can be
    // controlled using the button
    import javafx.application.Application;
    import javafx.scene.Scene;
    import javafx.scene.control.*;
    import javafx.scene.layout.*;
    import javafx.stage.Stage;
    import javafx.scene.image.*;
    import javafx.scene.effect.*;
    import java.io.*;
    import javafx.event.ActionEvent;
    import javafx.event.EventHandler;
    import javafx.scene.Group;
    public class bloom_2 extends Application {
    double level = 0.1 ;
    // launch the application
    public void start(Stage stage) throws Exception
    {
    // set title for the stage
    stage.setTitle( "Bloom Example" );
    // create a input stream
    FileInputStream input = new FileInputStream( "D:\GFG.png" );
    // create a image
    Image image = new Image(input);
    // create a image View
    ImageView imageview = new ImageView(image);
    // create a bloom effect
    Bloom bloom = new Bloom(level);
    // create a button
    Button button = new Button( "bloom" );
    // action event
    EventHandler<ActionEvent> event = new EventHandler<ActionEvent>() {
    public void handle(ActionEvent e)
    {
    // increase the level
    level += 0.1 ;
    if (level > 1 )
    level = 0.0 ;
    // set Level for bloom
    bloom.setThreshold(level);
    }
    };
    // set on action of button
    button.setOnAction(event);
    // set effect
    imageview.setEffect(bloom);
    // create a VBox
    VBox vbox = new VBox(imageview, button);
    // create a scene
    Scene scene = new Scene(vbox, 200 , 200 );
    // set the scene
    stage.setScene(scene);
    stage.show();
    }
    // Main Method
    public static void main(String args[])
    {
    // launch the application
    launch(args);
    }
    }

    
    

    输入图像: 图片[1]-JavaFX | Bloom类-yiteyi-C++库

    输出:

注: 上述程序可能无法在联机IDE中运行。请使用脱机编译器。

参考: https://docs.oracle.com/javase/8/javafx/api/javafx/scene/effect/Bloom.html

© 版权声明
THE END
喜欢就支持一下吧
点赞15 分享