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
Sub GetARGB(Color As Int) As Int()
Private res(4) As Int
res(0) = Bit.UnsignedShiftRight(Bit.And(Color, 0xff000000), 24)
res(1) = Bit.UnsignedShiftRight(Bit.And(Color, 0xff0000), 16)
res(2) = Bit.UnsignedShiftRight(Bit.And(Color, 0xff00), 8)
res(3) = Bit.And(Color, 0xff)
Return res
End Sub
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
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