裁剪一个填充径向渐变的矩形,使角变圆

问题描述 投票:0回答:1

环境:

我想在我的 JavaFX 应用程序 UI 中发出一些蓝光:

当我尝试使用带有

rectangle
rounded corners
radial gradient fill
来实现这一点时,这个(见图)角不透明。

但是如果我将矩形的填充更改为纯色(例如:

Color.RED
),那么这个角将是透明的并且将正确渲染...为什么它在径向渐变填充的情况下不起作用?

现在我使用这段代码:

RadialGradient gradient = new RadialGradient(
        0D, 0D, 34D, 250D, 231D, false, CycleMethod.NO_CYCLE,
        new Stop(0D, Color.rgb(0, 102, 254, 0.2D)),
        new Stop(100D, Color.rgb(0, 102, 254, 0D))
);

Rectangle light = new Rectangle(280D, 280D);
// I've tried to make 'light' rectangle corners round:
// light.setArcWidth(14D);
// light.setArcHeight(14D);
light.setFill(gradient);

// ... and also tried to make some new clip with round corners
Rectangle clip = new Rectangle(280D, 280D);
clip.setArcWidth(14D);
clip.setArcHeight(14D);

// ... and apply that to the 'light' rectangle, but it hasn't an effect :(
light.setClip(clip);

// after that light will be a children node of the parent StackPane
// this StackPane is a parent element of the all application 
// (provided to the Scene instance)
java javafx clip radial-gradients
1个回答
0
投票

哈哈,对不起:D

我之前不知道应该使用圆弧参数作为角

radius * 2
。我只是在
28
14
中使用
arc width
而不是
arc height
,这是我的问题的解决方案。

© www.soinside.com 2019 - 2024. All rights reserved.