gpt4 book ai didi

java - 将 BlendMode 添加到 JavaFX 中的裁剪节点

转载 作者:搜寻专家 更新时间:2023-11-01 03:16:41 25 4
gpt4 key购买 nike

有没有办法将 BlendMode(或 Blend 效果)添加到已被裁剪的节点?似乎如果我尝试将剪辑添加到已设置 BlendMode 的节点,则 BlendMode 会被剪辑覆盖并且不再正常工作。重现问题的一些示例代码:

package display.fx.demo;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.effect.BlendMode;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;

public class BlendModeClipProblem extends Application {
public Rectangle blueRect = new Rectangle(0, 0, 30, 30);
public Rectangle redRect = new Rectangle(15, 15, 30, 30);

@Override
public void start(final Stage stage)
throws Exception {
final Pane pane = new Pane();
final Scene scene = new Scene(pane);
pane.getChildren().add(blueRect);
pane.getChildren().add(redRect);

blueRect.setFill(Color.BLUE);
redRect.setFill(Color.RED);

redRect.setBlendMode(BlendMode.ADD);

// Comment this next line to see blending
redRect.setClip(new Rectangle(15, 15, 20, 20));

stage.setScene(scene);
stage.show();
}
}

最佳答案

尝试这样的事情(使用缓存矩形)

@Override
public void start(final Stage stage)
throws Exception {
final Pane pane = new Pane();
final Scene scene = new Scene(pane);
pane.getChildren().add(blueRect);
pane.getChildren().add(redRect);

blueRect.setFill(Color.BLUE);
redRect.setFill(Color.RED);

redRect.setBlendMode(BlendMode.ADD);

redRect.setCache(true);
redRect.setCacheHint(CacheHint.QUALITY);

redRect.setClip(new Rectangle(15, 15, 20, 20));

stage.setScene(scene);
stage.show();
}

关于java - 将 BlendMode 添加到 JavaFX 中的裁剪节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47783454/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com