JavaFX | MotionBlur类

MotionBlur是JavaFX的一部分。MotionBlur类使用高斯卷积核实现运动模糊效果,具有可配置的半径和角度。MotionBlur类继承 效应

null

类的构造函数:

  1. MotionBlur() :创建MotionBlur的新对象。
  2. MotionBlur(双a,双r) :创建具有指定角度和半径的MotionBlur新对象。

常用方法:

方法 解释
getAngle() 返回MotionBlur对象的角度
getRadius() 返回MotionBlur对象的半径
getInput() 返回MotionBlur对象的输入
设定角(双v) 设置MotionBlur对象的角度
getRadius(双v) 设置MotionBlur对象的半径
设置输入(效果v) 设置MotionBlur对象的输入

下面的程序演示了MotionBlur类的使用:

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

    // Java program to import an image and
    // add Motion Blur 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 motion_blur_1 extends Application {
    // launch the application
    public void start(Stage stage) throws Exception
    {
    // set title for the stage
    stage.setTitle( "MotionBlur 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 Motion blur effect
    MotionBlur motion_blur = new MotionBlur();
    // set effect
    imageview.setEffect(motion_blur);
    // 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 | MotionBlur类-yiteyi-C++库

    输出: 图片[2]-JavaFX | MotionBlur类-yiteyi-C++库

  2. 用于导入图像并使用指定角度和半径向其添加运动模糊效果的Java程序: 在这个节目中 文件输入流类 创建并从文件中获取图像作为输入。图像名为 形象 使用文件输入流中的输入创建。从图片上看,一个 图像视图对象 创建并将其添加到 VBox 这个 VBox 然后被添加到场景中,场景被添加到舞台上。A. 运动模糊 使用作为参数传递的指定级别创建效果,并使用 setEffect() 作用运动模糊的半径和角度是使用 setRadius() 设定角() 作用

    // Java program to import an image and
    // add Motion Blur effect to it with
    // specified angle and radius
    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 motion_blur_2 extends Application {
    // launch the application
    public void start(Stage stage) throws Exception
    {
    // set title for the stage
    stage.setTitle( "MotionBlur 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 Motion blur effect
    MotionBlur motion_blur = new MotionBlur();
    // set Radius
    motion_blur.setRadius( 25 .0f);
    // set angle
    motion_blur.setAngle( 400 .0f);
    // set effect
    imageview.setEffect(motion_blur);
    // 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 | MotionBlur类-yiteyi-C++库

    输出: 图片[4]-JavaFX | MotionBlur类-yiteyi-C++库

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

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

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