iOS Question how to convert panel color to rgb ?

bagazhou

Member
Licensed User
HI

i want to use ColorTemplate.SelectedColor to set color to panel, and how to use panel color to drawline ? thanks

B4X:
   Dialog.Title = "select color"
   
   Wait For (Dialog.ShowTemplate(ColorTemplate, "OK", "", "Exit")) Complete (Result As Int)
   If Result = XUI.DialogResponse_Positive Then
       Log("ColorTemplate.SelectedColor:" & ColorTemplate.SelectedColor)
       
      PanelColorCurrent.Color = ColorTemplate.SelectedColor
   
      'in this line , how to change panel color to rgb?
      'Canv.DrawLine(oldX, oldY, newX, newY, Colors.ARGB(color_A,color_R,color_G,color_B), 5)
      'Canv.Refresh

       
   End If
 

emexes

Expert
Licensed User
The bit-shifting approach works fine, but does have an edgy feel about it due to Int being signed.

The ByteConverter library has methods specifically for packing and unpacking different-sized variables, and is often better suited to the task (admittedly, for this particular example, it's a 51:49 toss-up... but I'd argue that generally: consistent approach = simpler programming life):
B4X:
Sub GetARGB(Color As Int) As Byte()
    Dim bc As ByteConverter
    Dim ColorComponents() As Byte = bc.IntsToBytes(Array As Int(Color))    'split 32-bit Color Int into four 8-bit bytes
    Return ColorComponents
End Sub
 
Last edited:

emexes

Expert
Licensed User
or even, no need for temporary array, so could just be:
B4X:
Sub GetARGB(Color As Int) As Byte()
    Dim bc As ByteConverter
    return bc.IntsToBytes(Array As Int(Color))    'split 32-bit Color Int into four 8-bit bytes
End Sub
 
Top