Sub Class_Globals
Private Root As B4XView
Private xui As XUI
Private ImageView1 As B4XView
Private ImageView2 As B4XView
End Sub
Public Sub Initialize
B4XPages.GetManager.LogEvents = True
End Sub
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
End Sub
'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
Private Sub Button1_Click
Dim bmp As B4XBitmap
Dim colourlist As Map
colourlist.Initialize
bmp = ImageView1.GetBitmap
bmp = bmp.Resize (320, 240, True)
bmp = BinColors (bmp) 'Change bitmap to 16 colours
colourlist = GetColours (bmp)
bmp = bmp.Resize (ImageView2.Width, ImageView2.Height,True) 'resize and display image
ImageView2.SetBitmap (bmp)
Log (colourlist) 'Always the same no matter what bitmap I use
End Sub
Private Sub CreateBC(bmp As B4XBitmap) As BitmapCreator
Dim bc As BitmapCreator
bc.Initialize(bmp.Width / bmp.Scale, bmp.Height / bmp.Scale)
bc.CopyPixelsFromBitmap(bmp)
Return bc
End Sub
Public Sub BinColors (bmp As B4XBitmap) As B4XBitmap
Dim bc As BitmapCreator = CreateBC(bmp)
Dim argb As ARGBColor
For x = 0 To bc.mWidth - 1
For y = 0 To bc.mHeight - 1
bc.GetARGB(x, y, argb)
argb.r = argb.r - (argb.r Mod 128)
argb.g = argb.g - (argb.g Mod 128)
argb.b = argb.b - (argb.b Mod 128)
bc.SetARGB(x, y, argb)
Next
Next
Return bc.Bitmap
End Sub
Sub GetColours (bmp As B4XBitmap) As Map
Dim m As Map
m.Initialize
Dim x As Int
Dim bc As BitmapCreator = CreateBC(bmp)
For x = 0 To bc.mWidth - 1 'Create a list of all the colors in the bitmap
For y = 0 To bc.mHeight - 1
m.Put (Bit.ToHexString (bc.GetColor(x,y)), Bit.ToHexString (bc.GetColor(x,y)))
Next
Next
Return m
End Sub