📜  JavaFX SepiaTone效果

📅  最后修改于: 2020-10-14 01:39:03             🧑  作者: Mango

JavaFX SepiaTone效果

SepiaTone效果基本上将图像的色调更改为红棕色。在JavaFX中,类javafx.scene.effect.SepiaTone表示SepiaTone效果。我们只需要实例化此类即可产生适当的效果。

物产

下表描述了该类的属性以及setter方法。

Property Description Setter Methods
input This is a Effect (Object) type property. It represents the input for this effect. setInput(Effect value)
level This is a double type property. It represents level value which control the intensity of the sepia effect. setLevel(Double value)

建设者

该类包含两个构造函数

  • public Sepiatone():使用默认参数创建一个新实例
  • public Sepiatone(double level):创建一个具有指定级别值的新实例。

例:

package application;
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.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontPosture;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.Stage;
public class SepiaToneExample extends Application{
@Override
public void start(Stage primaryStage) throws Exception {
// TODO Auto-generated method stub
Image img1 = new Image("https://www.javatpoint.com/linux/images/linux-first.png");
Image img2 = new Image("https://www.javatpoint.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("Original Image");
text2.setText("SepiaTone Effect Applied");
text1.setX(70);
text1.setY(300);
text2.setX(305);
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(70);
imgview1.setY(90);
imgview2.setX(300);
imgview2.setY(90);
SepiaTone sepia = new SepiaTone();
sepia.setLevel(0.75);
imgview2.setEffect(sepia);
Group root = new Group();
root.getChildren().addAll(imgview1,imgview2,text1,text2);
Scene scene = new Scene(root,600,350);
primaryStage.setScene(scene);
primaryStage.setTitle("Sepia Tone Effect Example");
primaryStage.show();

}
public static void main(String[] args) {
launch(args);
}
}