个性化阅读
专注于IT技术分析

JavaFX高斯模糊效果

本文概述

高斯模糊效应与BoxBlur效应非常相似。两者之间的唯一区别是, 高斯模糊效应使用高斯卷积核来模糊节点。但是, JavaFX提供了类javafx.scene.effect.GaussianBlur来在节点上实现GaussianBlur。需要实例化此类, 以便在节点上施加适当的效果。

物产

下表描述了该类的属性以及setter方法。

属性 描述 设置方法
input 此属性是效果类型。它代表效果的输入。 setInput(Effect value)
radius 此属性是双精度类型。它代表模糊内核的半径。 setRadius(Double value)

建设者

该类包含两个构造函数。

  1. public GaussianBlur():使用参数的默认值创建新实例。
  2. public GaussianBlur(double radius):使用指定的参数值创建一个新实例。

例:

package application;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.effect.BoxBlur;
import javafx.scene.effect.GaussianBlur;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontPosture;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.Stage;
public class GaussianBlurExample extends Application{

	@Override
	public void start(Stage primaryStage) throws Exception {
		// TODO Auto-generated method stub
		Text text = new Text();
		text.setText("Welcome to srcmini");
		text.setX(100);
		text.setY(100);
		text.setFont(Font.font("Calibri", FontWeight.BLACK, FontPosture.ITALIC, 20));
		text.setFill(Color.RED);
		text.setStroke(Color.BLACK);
		text.setUnderline(true);
		GaussianBlur g = new GaussianBlur();
		g.setRadius(5);
		text.setEffect(g);
		Group root = new Group();
		root.getChildren().add(text);
		Scene scene = new Scene(root, 450, 200);
		primaryStage.setScene(scene);
		primaryStage.setTitle("GaussianBlur Example");
		primaryStage.show();
	}
public static void main(String[] args) {
	launch(args);
}
}
JavaFX高斯模糊效果
赞(0)
未经允许不得转载:srcmini » JavaFX高斯模糊效果

相关推荐

评论 抢沙发

评论前必须登录!