个性化阅读
专注于IT技术分析

JavaFX ColorAdjust效果

本文概述

JavaFX允许我们通过调整图像色彩的诸如色相, 饱和度, 亮度和对比度的属性来调整图像的色彩。类javafx.scene.effect.ColorAdjust包含各种属性和方法, 可用于在节点上应用ColorAdjust效果。

物产

下面描述了类javafx.scene.effect.ColorAdjust的属性及其设置方法。

属性 描述 设置方法
brightness 调整颜色的亮度。这是一个双精度类型的属性。 setBrightness(double value)
contrast 根据颜色进行调整。它具有double类型的属性。 setContrast(double value)
hue 调整颜色的色调。它具有double类型的属性。 setHue(double value)
input 效果的输入值。它具有double类型的属性。 setInput(double value)
saturation 调整色彩饱和度。它具有double类型的属性。 setSaturation(double value)

建设者

该类包含下面给出的两个构造函数。

  1. public ColorAdjust():使用默认参数创建ColorAdjust的新实例。
  2. public ColorAdjust(双色调, 双饱和度, 双亮度, 双对比度):使用指定的参数创建ColorAdjust的新实例。

例:

在下面的示例中, ColorAdjust效果已应用于具有某些属性的图像。显示效果图像和原始图像之间的比较作为输出。

package application;
import javafx.application.Application;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
import javafx.scene.text.FontPosture;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.effect.ColorAdjust;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
public class ColorAdjustEffect extends Application{

	@Override
	public void start(Stage primaryStage) throws Exception {
		// TODO Auto-generated method stub
		Image img1 = new Image("https://www.srcmini02.com/linux/images/linux-first.png");
		Image img2 = new Image("https://www.srcmini02.com/linux/images/linux-first.png");
		ImageView imgview1 = new ImageView(img1);
		ImageView imgview2 = new ImageView(img2);
		Text text1 = new Text();
		Text text2 = new Text();
		text1.setText("ColorAdjust Effect Applied");
		text2.setText("ColorAdjust Effect Not Applied");
		text1.setX(50);
		text1.setY(300);
		text2.setX(355);
		text2.setY(300);
		text1.setFont(Font.font("Courier 10 Pitch", FontWeight.BOLD, FontPosture.REGULAR, 16));
		text2.setFont(Font.font("Courier 10 Pitch", FontWeight.BOLD, FontPosture.REGULAR, 16));
		text1.setFill(Color.RED);
		text2.setFill(Color.RED);
		text1.setStroke(Color.BLACK);
		text2.setStroke(Color.BLACK);
		text1.setStrokeWidth(0.2);
		text2.setStrokeWidth(0.2);
		
		imgview1.setX(100);
		imgview1.setY(90);
		imgview2.setX(400);
		imgview2.setY(90);
		ColorAdjust c = new ColorAdjust(); // creating the instance of the ColorAdjust effect. 
		c.setBrightness(0.2); // setting the brightness of the color. 
		c.setContrast(0.1); // setting the contrast of the color
		c.setHue(0.3); // setting the hue of the color
		c.setSaturation(0.45); // setting the hue of the color. 
		imgview1.setEffect(c); //applying effect on the image
		
		Group root = new Group();
		
		root.getChildren().addAll(imgview1, imgview2, text1, text2);
		Scene scene = new Scene(root, 700, 400);
		primaryStage.setScene(scene);

		primaryStage.setTitle("ColorAdjust Effect Example");
		primaryStage.show();
		
	}
public static void main(String[] args) {
	launch(args);
}
}
JavaFX ColorAdjust效果
赞(0)
未经允许不得转载:srcmini » JavaFX ColorAdjust效果

相关推荐

评论 抢沙发

评论前必须登录!