Javafx-glow-effect

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

JavaFXエフェクト-グロー

ブルームエフェクトと同様に、グローエフェクトも指定された入力画像をグローにします。 この効果により、入力のピクセルが非常に明るくなります。

パッケージ javafx.scene.effectGlow という名前のクラスは、グロー効果を表します。 このクラスには2つのプロパティが含まれています-

  • input -このプロパティはEffect型であり、グロー効果への入力を表します。
  • レベル-このプロパティはdouble型です。グローの強度を表します。 レベル値の範囲は0.0〜1.0です。

次のプログラムは、JavaFXのグロー効果を示す例です。 ここでは、 Image および ImageView クラスを使用して、JavaFXシーンに次の画像(finddevguidesロゴ)を埋め込みます。 これは、位置100、70で、それぞれ適合高さおよび適合幅200および400で行われます。

グロー効果

この画像に、レベル値0.9のグロー効果を適用しています。 このコードを GlowEffectExample.java という名前のファイルに保存します。

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.effect.Glow;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.stage.Stage;

public class GlowEffectExample extends Application {
   @Override
   public void start(Stage stage) {
     //Creating an image
      Image image = new Image("http://www.finddevguides.com/green/images/logo.png");

     //Setting the image view
      ImageView imageView = new ImageView(image);

     //setting the fit width of the image view
      imageView.setFitWidth(200);

     //Setting the preserve ratio of the image view
      imageView.setPreserveRatio(true);

     //Instantiating the Glow class
      Glow glow = new Glow();

     //setting level of the glow effect
      glow.setLevel(0.9);

     //Applying bloom effect to text
      imageView.setEffect(glow);

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

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

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

グロー効果の例