Javafx-box-blur-effect

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

JavaFXエフェクト-ボックスぼかし

一般に、ぼかしは不明瞭になることを意味し、ノードにぼかし効果を適用すると不明瞭になります。 Box Blurは、JavaFXが提供するぼかし効果の一種です。 この効果では、ノードにぼかしを適用するために、単純なボックスフィルターが使用されます。

パッケージ javafx.scene.effectBoxBlur という名前のクラスは、BoxBlurエフェクトを表します。このクラスには4つのプロパティが含まれています。

  • height -このプロパティは、効果の垂直方向のサイズを表すdouble型です。
  • -このプロパティは、効果の水平方向のサイズを表すdouble型です。
  • input -このプロパティは型効果であり、BoxBlur効果への入力を表します。
  • iterations -このプロパティは、ノードに適用されるエフェクトの反復回数を表す整数型です。 これは、品質または滑らかさを改善するために行われます。

以下は、ボックスのぼかし効果を示す例です。 ここでは、DARKSEAGREENカラーで塗りつぶされたテキスト「Welcome to finddevguides」を描画し、それにボックスブラーエフェクトを適用しています。

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

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

public class BoxBlurEffectExample 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 BoxBlur class
      BoxBlur boxblur = new BoxBlur();

     //Setting the width of the box filter
      boxblur.setWidth(8.0f);

     //Setting the height of the box filter
      boxblur.setHeight(3.0f);

     //Setting the no of iterations
      boxblur.setIterations(3);

     //Applying BoxBlur effect to the text
      text.setEffect(boxblur);

     //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 BoxBlurEffectExample.java
java BoxBlurEffectExample

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

ボックスぼかし効果