Javafx-gaussianblur-effect

提供:Dev Guides
移動先:案内検索

JavaFXエフェクト-ガウスぼかし

ボックスブラーと同様に、ガウスはJavaFXのノードをぼかす効果です。 唯一の違いは、*ガウスぼかし効果*では、ぼかし効果を生成するためにガウス畳み込みカーネルが使用されることです。

パッケージのGaussianBlurというクラス javafx.scene.effect は、ガウスぼかし効果を表し、このクラスには2つのプロパティが含まれています-

  • input -このプロパティはEffect型であり、ボックスブラー効果への入力を表します。
  • 半径-このプロパティは、*ガウスぼかし効果*が適用される半径を表すダブルタイプです。 ぼかし効果は半径に直接比例します。

次のプログラムは、ガウスぼかし効果を示す例です。 この例では、DARKSEAGREEN色で塗りつぶされたテキスト「Welcome to finddevguides」を描画し、それにガウスぼかし効果を適用しています。

このコードを GaussianBlurEffectExample.java という名前のファイルに保存します。

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.scene.effect.GaussianBlur;

public class GaussianBlurEffectExample extends Application {
   @Override
   public void start(Stage stage) {
     //Creating a Text object
      Text text = new Text();

     //Setting font to the text
      text.setFont(Font.font(null, FontWeight.BOLD, 40));

     //setting the position of the text
      text.setX(60);
      text.setY(150);

     //Setting the text to be added.
      text.setText("Welcome to finddevguides");

     //Setting the color of the text
      text.setFill(Color.DARKSEAGREEN);

     //Instantiating the GaussianBlur class
      GaussianBlur gaussianBlur = new GaussianBlur();

     //Setting the radius to apply the Gaussian Blur effect
      gaussianBlur.setRadius(10.5);

     //Applying Gaussian Blur effect to the text
      text.setEffect(gaussianBlur);

     //Creating a Group object
      Group root = new Group(text);

     //Creating a scene object
      Scene scene = new Scene(root, 600, 300);

     //Setting title to the Stage
      stage.setTitle("Sample Application");

     //Adding scene to the stage
      stage.setScene(scene);

     //Displaying the contents of the stage
      stage.show();
   }
   public static void main(String args[]){
      launch(args);
   }
}

次のコマンドを使用して、コマンドプロンプトから保存したJavaファイルをコンパイルして実行します。

javac GaussianBlurEffectExample.java
java GaussianBlurEffectExample

実行時に、上記のプログラムは以下に示すようにJavaFXウィンドウを生成します。

ガウスぼかし効果