2 Using the Bloom Effect

转自: http://docs.oracle.com/javafx/2/visual_effects/bloom.htm

The bloom effect makes brighter portions(部分) an image appear to glow, based on a configurable threshold. The threshold(阈值) varies from 0.0 to 1.0. By default, the threshold is set to 0.3.

Figure 2-1 shows the bloom effect at the default threshold and at a threshold of 1.0.

Example 2-1 shows a code snippet from the sample application that is using the bloom effect

package visualEffects;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.effect.Bloom;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class TestBloom extends Application{
	public static void main(String[] args) {
		launch(args);
	}

	@Override
	public void start(Stage stage) throws Exception {
		Node node = bloom();
		Scene s = new Scene((Parent)node,1000,500);
		stage.setScene(s);
		stage.show();
		
	}
	  static Parent bloom() {
	        final Group g = new Group();
	 
	        Rectangle r = new Rectangle();
	        r.setX(10);
	        r.setY(10);
	        r.setWidth(160);
	        r.setHeight(80);
	        r.setFill(Color.DARKBLUE);
	 
	        Text t = new Text();
	        t.setText("Bloom!");
	        t.setFill(Color.YELLOW);
	        t.setFont(Font.font("null", FontWeight.BOLD, 36));
	        t.setX(25);
	        t.setY(65);
	        Button button2 = new Button("点击");
	        button2.setOnAction(new EventHandler<ActionEvent>() {
	            @Override public void handle(ActionEvent e) {
	            	 g.setTranslateX(350);
	            }
	        });
	        g.setCache(true);
	        //g.setEffect(new Bloom());
	        Bloom bloom = new Bloom();
	        bloom.setThreshold(0.5);
	        g.setEffect(bloom);
	        g.getChildren().add(r);
	        g.getChildren().add(t);
	        g.getChildren().add(button2);
//	        g.setTranslateX(350);
	        return g;
	    }
}

运行结果:


如果调整为1.0,效果如下:



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值