📜  JavaFX 混合效果

📅  最后修改于: 2020-10-14 01:29:54             🧑  作者: Mango

JavaFX混合效果

通常,混合效果产生的输出是由于两个或多个不同输入节点的混合而产生的。它需要两个或更多节点的像素,根据所应用的混合模式对其进行混合,并在同一位置生成输出节点。

如果两个图像相互重叠,则将混合模式应用于两个图像的重叠区域。

物产

该类包含四个属性,这些属性及其下表中的setter方法进行了描述。

Property Description Setter Methods
bottomInput The bottom input for the blend operation. This is a object type property. setBottomInput(Effect value)
mode The mode according to which, the inputs are blend together. setMode(BlendMode value)
opacity This is the opacity value of double type. setOpacity(double value)
topInput The top input for the blend operation. setTopInput(Effect Value)

建设者

此类中有三个构造函数。

  • Blend():使用默认值实例化Blend类。
  • Blend(BlendMode模式):以指定模式实例化Blend类
  • Blend(BlendMode模式,BottomInput效果,TopInput效果):使用指定的混合模式,Bottom Input效果和Top Input效果实例化Blend类。

例:

package application;
import javafx.application.Application; 
import javafx.scene.Group; 
import javafx.scene.Scene; 
import javafx.stage.Stage;
import javafx.scene.shape.Circle; 
import javafx.scene.effect.Blend; 
import javafx.scene.effect.BlendMode; 
import javafx.scene.effect.ColorInput; 
import javafx.scene.paint.Color; 

public class BlendExample extends Application { 
@Override
public void start(Stage primaryStage) { 
Circle circle = new Circle(150,200,120);       
circle.setFill(Color.RED); 
Blend blend = new Blend();  
ColorInput color = new ColorInput(70, 20, 160, 150, Color.LIMEGREEN);
blend.setTopInput(color);
blend.setMode(BlendMode.ADD);   
circle.setEffect(blend);       
Group root = new Group(circle); 
Scene scene = new Scene(root, 300,350);  
primaryStage.setTitle("Blend Example"); 
primaryStage.setScene(scene); 
primaryStage.show(); 
}      
publicstaticvoid main(String args[]){ 
launch(args); 
} 
} 

混合模式

JavaFX提供了各种混合模式,可以使用它们来修改混合效果。

Blend Mode Description Output
Add The color components of the top input are added to that from the bottom input. JavaFX Blend Mode Add Output
Blue Only Blue components of the bottom input gets replaced by the blue component of top input. JavaFX Blend Mode Blue Output
COLOR_BURN The bottom input color gets inverted and divided by the top input color components. The result is again inverted to get the output color. JavaFX Blend Mode COLORBURN Output
COLOR_DODGE The top color components gets inverted and divide the bottom color components to produce the output color. JavaFX Blend Mode COLOR DODGE Output
DARKEN The color which is darker of the two input component colors is selected to produce the resulting color. JavaFX Blend Mode DARKEN Output
DIFFERENCE The darker of the two input color is subtracted from the lighter color to produce the resulting color. JavaFX Blend Mode DIFFERENCE Output
EXCLUSION The two input color components are multiplied and doubled and then subtracted from the sum of bottom color components to produce the desired color. JavaFX Blend Mode EXCLUSION Output
GREEN The green component from the bottom input is replaced by the green input of top component. JavaFX Blend Mode GREEN Output
HARD_LIGHT The input color components are either multiplied or screened depending upon the bottom color. JavaFX Blend Mode HARD LIGHT Output
LIGHTEN The lighter color of the two color components is produced as output. JavaFX Blend Mode LIGHTEN Output
MULTIPLY Both the color components get multiplied to produce the output color. JavaFX Blend Mode MULTIPLY Output
OVERLAY The input color components gets either screened or multiplied depending upon the bottom color. JavaFX Blend Mode OVERLAY Output
RED The red components of bottom input gets replaced with the red components of top input. JavaFX Blend Mode RED Output
SCREEN Both color components are inverted, multiplied and again inverted to produce the desired result. JavaFX Blend Mode SCREEN Output
SOFT_LIGHT The input color components become lighten or darken. JavaFX Blend Mode SOFT LIGHT Output
SRC_ATOP The part of the top input that is lying over the bottom input gets blended. JavaFX Blend Mode SRC ATOP Output
SRC_OVER Top input gets blended over bottom input. JavaFX Blend Mode SRC OVER Output