[英]Clipping a rectangle filled with radial gradient to make corners round
Environment:环境:
I want to make some blue light in my JavaFX application UI:我想在我的 JavaFX 应用程序 UI 中发出一些蓝光:
When I try to make that using a rectangle
with rounded corners
and radial gradient fill
, this (see picture) corner isn't transparent.当我尝试使用带有rounded corners
和radial gradient fill
的rectangle
来制作它时,这个(见图)角不透明。
BUT If I will change rectangle's fill to someone solid color (ex: Color.RED
) then this corner will be transparent and will be rendered correctly... Why it doesn't working in the case with radial gradient fill?但是如果我将矩形的填充更改为纯色(例如: Color.RED
),那么这个角将是透明的并且将被正确渲染......为什么它在径向渐变填充的情况下不起作用?
Now I using this code:现在我使用这段代码:
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)
Lol, I am sorry :D大声笑,我很抱歉:D
I don't know before that I should to use arc parameters as corner radius * 2
.我之前不知道我应该使用圆弧参数作为圆角radius * 2
。 I've just use 28
instead of 14
in the arc width
and arc height
and it's a solution of my problem.我只是在arc width
和arc height
使用了28
而不是14
,这解决了我的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.