Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim ImageView1 As ImageView
Dim Button1 As Button
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("Layout1")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub getambiencecolor(b As Bitmap,x1,y1,x2,y2 As Int) As Int
Dim argb() As Int
Dim i,j As Int
Dim ta,tr,tg,tb,aa,ar,ag,ab As Int
Dim numberofpixel,ambiencecolor As Int
Dim ca,cr,cg,cb As Int
Dim colorvalue As Int
ta=0
tr=0
tg=0
tb=0
numberofpixel=0
For i=x1 To x2
For j=y1 To y2
colorvalue=b.getPixel(i,j)
argb = GetARGB(colorvalue)
ca=argb(0)
cr=argb(1)
cg=argb(2)
cb=argb(3)
ta=ta+ca
tr=tr+cr
tg=tg+cg
tb=tb+cb
numberofpixel=numberofpixel+1
Next
Next
aa=ta/numberofpixel
ar=tr/numberofpixel
ag=tg/numberofpixel
ab=tb/numberofpixel
ambiencecolor=Colors.argb(aa,ar,ag,ab)
Return ambiencecolor
End Sub
Sub Button1_Click
Dim btmp As Bitmap
Dim rect1 As Rect
Dim c As Canvas
Dim ambiencecolor As Int
btmp.Initialize(File.DirAssets,"flower.png")
ambiencecolor=getambiencecolor(btmp,129,86,153,106)
ImageView1.Bitmap=btmp
ImageView1.Width=btmp.Width
ImageView1.Height=btmp.Height
'Draw a rect using ambiencecolor
rect1.Initialize(10,10,50,50)
c.Initialize(ImageView1)
c.DrawRect(rect1,ambiencecolor,True,1)
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