Javafx-sepiatone-effect

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

JavaFXエフェクト-SepiaTone

JavaFXのノード(一般的なイメージ)にセピアトーン効果を適用すると、赤褐色の色調になります。

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

  • レベル-このプロパティは、この効果の強度を表すダブルタイプです。 このプロパティの範囲は0.0〜1.0です。
  • input -このプロパティはタイプ効果であり、セピアトーン効果への入力を表します。

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

SepiaTone

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

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

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

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

     //Setting the position of the image
      imageView.setX(150);
      imageView.setY(0);

     //setting the fit height and width of the image view
      imageView.setFitHeight(300);
      imageView.setFitWidth(400);

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

     //Instanting the SepiaTone class
      SepiaTone sepiaTone = new SepiaTone();

     //Setting the level of the effect
      sepiaTone.setLevel(0.8);

     //Applying SepiaTone effect to the image
      imageView.setEffect(sepiaTone);

     //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("Sepia tone effect example");

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

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

SepiaTone Effect