Javafx 简明教程
JavaFX - Smooth Property
Smoothing 是统计学或图像处理中更常见的过程。它被定义为将坐标或数据点与其序列(如时间序列或图像)中的邻近点进行平均的过程。这会导致平滑数据中锐利边缘的效果。平滑有时被称为滤波,因为平滑具有抑制高频信号和增强低频信号的效果。
Smoothing is a more common process seen in Statistics or Image processing. It is defined as a process in which coordinates or data points are averaged with their neighbouring points of a series, such as a time series, or image. This results in the effect of blurring the sharp edges in the smoothed data. Smoothing is sometimes referred to as filtering, because smoothing has the effect of suppressing high frequency signal and enhancing low frequency signal.
平滑过程通常用于精细调整图像或数据集。在 JavaFX 中,使用此属性对 2D 形状将微调边缘。
The process of smoothing is done usually to fine scale an image or a data set. In JavaFX, using this property on 2D shapes will fine tune the edges.
Smooth Property
JavaFX 中的 smooth property 用于平滑某个 2D 形状的边缘。此属性为布尔类型。如果此值为 true,则形状的边缘将平滑。
The smooth property in JavaFX is used to smoothen the edges of a certain 2D shape. This property is of the type Boolean. If this value is true, then the edges of the shape will be smooth.
您可以使用 setSmooth() 方法为此属性设置值,如下所示 −
You can set value to this property using the method setSmooth() as follows −
path.setSmooth(false);
默认情况下,smooth 值为 true。以下是具有两种平滑值的三角形的图表。
By default, the smooth value is true. Following is a diagram of a triangle with both smooth values.
Example
在以下示例中,我们将尝试抚平 2D 形状(比如一个圆圈)的边。使用 SmoothExample.java 名称保存此文件。
In the following example, we will try to smoothen the edges of a 2D shape, say a circle. Save this file with the name SmoothExample.java.
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.shape.Circle;
import javafx.scene.shape.StrokeLineCap;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
public class SmoothExample extends Application {
@Override
public void start(Stage stage) {
//Creating a Circle
Circle circle = new Circle(150.0, 150.0, 100.0);
circle.setFill(Color.BLUE);
circle.setStroke(Color.BLACK);
circle.setStrokeWidth(5.0);
circle.setSmooth(true);
//Creating a Group object
Group root = new Group(circle);
//Creating a scene object
Scene scene = new Scene(root, 300, 300);
//Setting title to the Stage
stage.setTitle("Drawing a Circle");
//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 文件。
Compile and execute the saved java file from the command prompt using the following commands.
javac --module-path %PATH_TO_FX% --add-modules javafx.controls SmoothExample.java
java --module-path %PATH_TO_FX% --add-modules javafx.controls SmoothExample