B4J Question javafx scene paint paint to java.awt.color

Firpas

Active Member
Licensed User
Longtime User
Hi to everybody

Please any way to convert type javafx.scene.paint.Paint to java.awt.color ??

Thanks in advance
 

Firpas

Active Member
Licensed User
Longtime User
Thanks for your replay

I want to do Just the opposite javafx.scene.paint.Color to java.awt.Color
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Yes, it appears that Paint does not want to give up it's secrets too easily, fortunately Erel gave us a way. Try this:

B4X:
Public Sub PaintToAwtColor(Color As Paint) As Object
  
    Dim ColorInt As Int  = fx.Colors.To32Bit(Color)
    Dim A As Int = Bit.And(Bit.ShiftRight(ColorInt,24),0XFF)
    Dim R As Int = Bit.And(Bit.ShiftRight(ColorInt,16) ,0xFF)
    Dim G As Int = Bit.And(Bit.ShiftRight(ColorInt,8),0xFF)
    Dim B As Int = Bit.And(ColorInt,0xFF)
  
    Log(A & " : " & R & " : " & G & " : " & B)
  
    Dim JO As JavaObject
    JO.InitializeNewInstance("java.awt.Color",Array(R,G,B,A))
  
    Log("Check values")
    Log("Alpha " & JO.RunMethod("getAlpha",Null))
    Log("Red " & JO.RunMethod("getRed",Null))
    Log("Green " & JO.RunMethod("getGreen",Null))
    Log("Blue " & JO.RunMethod("getBlue",Null))
    Return JO
End Sub
 
Last edited:
Upvote 0
Top