多读书多实践,勤思考善领悟

JavaFX effect SepiaTone(深褐色调效果)

本文于1664天之前发表,文中内容可能已经过时。

在将深褐色调效果应用于JavaFX中的节点(一般图像)时,它采用红棕色调。

javafx.scene.effect的名为SepiaTone的类表示棕褐色调效果,此类包含两个属性,它们是 -

  • level - 此属性为double类型,表示此效果的强度。此属性的范围是0.0到1.0。
  • input - 此属性具有类型效果,它表示棕褐色调效果的输入。

以下程序是演示JavaFX的棕褐色调效果的示例。在这里,我们使用ImageImageView类在JavaFX场景中嵌入以下图像(tutorialspoint徽标)。这在位置100,70处完成,分别具有配合高度和配合宽度200和400。

SepiaTone

对于这张图片,我们正在应用具有级别值0.9的棕褐色调效果。将此代码保存在名为SepiaToneEffectExample.java的文件中。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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.tutorialspoint.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文件。

1
2
javac SepiaToneEffectExample.java 
java SepiaToneEffectExample

执行时,上面的程序生成一个JavaFX窗口,如下所示。