[英]Java: convert java.awt.Color to javafx.scene.paint.Color
How can I conver one to another? 我怎样才能相互融合? I thought a way via rgb string, but this case alpha layer is ignored.
我想通过rgb字符串的方式,但这种情况下alpha层被忽略。 So the question - how to convert one to another with alpha?
那么问题 - 如何使用alpha将一个转换为另一个?
Get each component from the awt Color object and use the javafx.scene.paint.Color.rgb(...)
static method. 从awt Color对象获取每个组件,并使用
javafx.scene.paint.Color.rgb(...)
静态方法。 Note that the awt Color has a getAlpha()
method that returns the alpha as an int
in the range 0-255
, whereas javafx.scene.paint.Color.rgb(...)
expects the alpha value as a double
in the range 0.0-1.0
: 请注意,awt Color有一个
getAlpha()
方法,它将alpha返回为0-255
范围内的int
,而javafx.scene.paint.Color.rgb(...)
则要求alpha值为范围内的double
值0.0-1.0
:
java.awt.Color awtColor = ... ;
int r = awtColor.getRed();
int g = awtColor.getGreen();
int b = awtColor.getBlue();
int a = awtColor.getAlpha();
double opacity = a / 255.0 ;
javafx.scene.paint.Color fxColor = javafx.scene.paint.Color.rgb(r, g, b, opacity);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.