Javafx 简明教程
JavaFX - Glow Effect
与 Bloom 效果一样,Glow 效果也能使给定的输入图像发光。这种效果使输入图像的像素更亮。
Just like the Bloom Effect, the Glow Effect also makes the given input image to glow. This effect makes the pixels of the input much brighter.
Glow 包 javafx.scene.effect 中的类表示发光效果。此类包含两个属性,即:
The class named Glow of the package javafx.scene.effect represents the glow effect. This class contains two properties namely −
-
input − This property is of the type Effect and it represents an input to the glow effect.
-
level − This property is of the type double; it represents intensity of the glow. The range of the level value is 0.0 to 1.0.
Example
以下程序是一个演示 JavaFX 发光效果的示例。在此,我们使用 Image 和 ImageView 类将以下图像(Tutorialspoint 徽标)嵌入 JavaFX 场景中。这将在位置 100、70 处完成,其高度和宽度分别适合值 200 和 400。
The following program is an example demonstrating the Glow Effect of JavaFX. In here, we are embedding the following image (Tutorialspoint Logo) in JavaFX scene using Image and ImageView classes. This will be done at the position 100, 70 and with fit height and fit width 200 and 400 respectively.
对于此图像,我们应用了级别值为 0.9 的发光效果。将此代码保存在名称为 GlowEffectExample.java 的文件中。
To this image, we are applying the Glow Effect with the level value 0.9. Save this code in a file with the name GlowEffectExample.java.
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.effect.Glow;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.stage.Stage;
public class GlowEffectExample extends Application {
@Override
public void start(Stage stage) {
//Creating an image
Image image = new Image("http://www.tutorialspoint.com/green/images/logo.png");
//Setting the image view
ImageView imageView = new ImageView(image);
//setting the fit width of the image view
imageView.setFitWidth(200);
//Setting the preserve ratio of the image view
imageView.setPreserveRatio(true);
//Instantiating the Glow class
Glow glow = new Glow();
//setting level of the glow effect
glow.setLevel(0.9);
//Applying bloom effect to text
imageView.setEffect(glow);
//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("Sample Application");
//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 GlowEffectExample.java
java --module-path %PATH_TO_FX% --add-modules javafx.controls GlowEffectExample