Reading .Color attribute of Button

moster67

Expert
Licensed User
Longtime User
Shay,

Have you tried the code given?

If not, then try to code the examples given to you and then revert back if it does not work indicating what is wrong.
 

Shay

Well-Known Member
Licensed User
Longtime User
I think all is now working
thanks for your help
:sign0060:
 

le_toubib

Active Member
Licensed User
Longtime User
Just to satisfy my curiousity, what part solved your problem?
hello there kickaha
I tried the same example that u gave :

<code>
code:
Sub tile_Click
Type labelData (Value AsInt, bCol AsInt)
Dim tiledata(25) As labelData

Dim tiles As Label
tiles= Sender
Dim tempdata As labelData
tempdata.Initialize
tempdata = tiles.Tag
<code/>

, but I got the following errors : in this line :tempdata = tiles.Tag
main$_labeldata cannot be cast to main$_labeldata

any explanation ???
 

derez

Expert
Licensed User
Longtime User
If you still want to get the color, here is how:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    b.Initialize("")
    Activity.AddView(b,10%x,10%y,30%x,20%y)
    b.Color = Colors.green
    Dim k As Int = ViewColor(b)
    Dim res() As Int
    res = GetARGB(k)
    Log(res(1) & " " & res(2) & " " & res(3))
End Sub

Sub ViewColor(v As View) As Int
   Dim cnvs As Canvas
   cnvs.Initialize(b)
  
   Return cnvs.Bitmap.GetPixel(1%x, 1%x)
End Sub

Sub GetARGB(Color As Int) As Int()
    Dim 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
 

le_toubib

Active Member
Licensed User
Longtime User
If you still want to get the color, here is how:
thanks for replying, that s a very useful method,
I could do it by assigning a list to the tag property and then retrieve it by a temp list.
however when I tried to do the same with a user defined type, it failed to cast upon retrieval
 
Top