JavaFX中effect包中Blend类简单使用
在JavaFX的类库中提供了许多特殊效果。在RIA应用它,可以具有更好的视觉。今天,我看看Blend类的使用。混合效果示例效果如图:
- /*
- * Main.fx
- *
- * Created on Dec 29, 2008, 9:50:06 PM
- */
- package effects;
- import javafx.scene.*;
- import javafx.scene.effect.Blend;
- import javafx.scene.effect.BlendMode;
- import javafx.scene.effect.Flood;
- import javafx.scene.paint.Color;
- import javafx.scene.paint.CycleMethod;
- import javafx.scene.paint.LinearGradient;
- import javafx.scene.paint.Stop;
- import javafx.scene.shape.Rectangle;
- import javafx.scene.text.Font;
- import javafx.scene.text.FontPosture;
- import javafx.scene.text.FontWeight;
- import javafx.scene.text.Text;
- import javafx.stage.Stage;
- /**
- * @author Administrator
- */
- var x:Integer=0;
- Stage {
- title: "Application title"
- width: 350
- height: 150
- scene: Scene {
- content:[
- Group{
- content:[
- for(x in [0..4]) {
- Rectangle {
- y: indexof x * 20
- width: 100
- height: 10
- fill: LinearGradient {
- startX: 0.0
- startY: 0.0
- endX: 0.25
- endY: 0.25
- cycleMethod: CycleMethod.REFLECT
- stops: [
- Stop {
- offset: 0.0
- color: Color.RED },
- Stop {
- offset: 1.0
- color: Color.YELLOW }
- ]
- }
- }
- }
- Text {
- effect: Blend {
- mode: BlendMode.SRC_OUT
- topInput: Flood {
- paint: Color.BLUE
- x: 10
- y: 10
- width: 160
- height: 80
- }
- }
- translateX:100;
- x: 25
- y: 65
- content: "SrcOut"
- fill: Color.BLUE
- font: Font.font(null, FontWeight.BOLD, FontPosture.ITALIC, 36);
- }
- ]
- }
- ]
- }
- }
在Retangle使用了LinerGradient效果,并且有五个长方形。而“SrcOut”使用Blend效果。
其中Blend类的主要属性有:
topInput:顶端输入;
bottomInput:末端输入;
mode:模式;
opacity:不透明度;
主要是把两种输入的颜色按一定的模式混合在一起。