Javafx-color-adjust-effect

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

JavaFXエフェクト-色調整

画像に色調整効果を適用して、画像の色を調整できます。 これには、各ピクセルの*色相、彩度、明るさ*および*コントラスト*の調整が含まれます。

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

  • input -このプロパティはEffectタイプであり、色調整エフェクトへの入力を表します。
  • 明るさ-このプロパティはDouble型で、この効果の明るさ調整値を表します。
  • contrast -このプロパティはDouble型で、この効果のコントラスト調整値を表します。
  • hue -このプロパティはDouble型で、この効果の色相調整値を表します。
  • 彩度-このプロパティはDouble型で、この効果の彩度調整値を表します。

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

画像ビュー

カラー調整効果を使用して、この画像の色を調整しています。 *コントラスト、色相、明度、彩度*の値は0.4です。 -0.05、0.9、0.8。

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

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

public class ColorAdjustEffectExample 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 position of the image
      imageView.setX(100);
      imageView.setY(70);

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

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

     //Instantiating the ColorAdjust class
      ColorAdjust colorAdjust = new ColorAdjust();

     //Setting the contrast value
      colorAdjust.setContrast(0.4);

     //Setting the hue value
      colorAdjust.setHue(-0.05);

     //Setting the brightness value
      colorAdjust.setBrightness(0.9);

     //Setting the saturation value
      colorAdjust.setSaturation(0.8);

     //Applying coloradjust effect to the ImageView node
      imageView.setEffect(colorAdjust);

     //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("Coloradjust 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 ColorAdjustEffectExample.java
java ColorAdjustEffectExample

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

ColorAdjust