How can I conver one to another? I thought a way via rgb string, but this case alpha layer is ignored. So the question - how to convert one to another with alpha?
Java: convert java.awt.Color to javafx.scene.paint.Color
Get each component from the awt Color object and use the javafx.scene.paint.Color.rgb(...)
static method. 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
:
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);
© 2022 - 2024 — McMap. All rights reserved.