目录

Glow

就像Bloom Effect一样,Glow Effect也会使给定的输入图像发光。 此效果使输入的像素更亮。

javafx.scene.effect名为Glow的类表示发光效果。 该类包含两个属性,即 -

  • input - 此属性的类型为Effect,它表示发光效果的输入。

  • level - 此属性的类型为double; 它代表了发光的强度。 级别值的范围是0.0到1.0。

例子 (Example)

以下程序是演示JavaFX的Glow效果的示例。 在这里,我们使用ImageImageView类在JavaFX场景中嵌入以下图像(IoWiki Logo)。 这将在位置100,70处完成,并且分别具有配合高度和配合宽度200和400。

发光效果

对于此图像,我们应用了Glow Effect,其级别值为0.9。 将此代码保存在名为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.iowiki.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文件。

javac GlowEffectExample.java 
java GlowEffectExample

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

发光效果示例
↑回到顶部↑
WIKI教程 @2018