Sub Process_Globals
Private MainForm As Form
Private xui As XUI
Private ImageView1 As ImageView
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("1") 'Load the layout file.
MainForm.Show
Dim large As B4XBitmap = xui.LoadBitmap(File.DirAssets, "main.png")
Dim small As B4XBitmap = xui.LoadBitmap(File.DirAssets, "small.png")
Dim r As B4XRect = IndexOfImage(large, small)
'just for the example:
Dim lbc As BitmapCreator
lbc.Initialize(large.Width, large.Height)
lbc.CopyPixelsFromBitmap(large)
If r.Width > 0 Then
lbc.DrawRect(r, xui.Color_Red, True, 0)
End If
lbc.SetBitmapToImageView(lbc.Bitmap, ImageView1)
End Sub
Sub IndexOfImage(Large As B4XBitmap, Small As B4XBitmap) As B4XRect
Dim lbc, sbc As BitmapCreator
lbc.Initialize(Large.Width, Large.Height)
lbc.CopyPixelsFromBitmap(Large)
sbc.Initialize(Small.Width, Small.Height)
sbc.CopyPixelsFromBitmap(Small)
Dim pm1, pm2 As PremultipliedColor
Dim r As B4XRect
For ly = 0 To lbc.mHeight - sbc.mHeight
For lx = 0 To lbc.mWidth - sbc.mWidth
If IsMatch(lbc, sbc, lx, ly, pm1, pm2) Then
r.Initialize(lx, ly, lx + sbc.mWidth, ly + sbc.mHeight)
Return r
End If
Next
Next
r.Initialize(0, 0, 0, 0)
Return r
End Sub
Sub IsMatch(lbc As BitmapCreator, sbc As BitmapCreator, lx As Int, ly As Int, pm1 As PremultipliedColor, pm2 As PremultipliedColor) As Boolean
For sy = 0 To sbc.mHeight - 1
For sx = 0 To sbc.mWidth - 1
sbc.GetPremultipliedColor(sx, sy, pm2)
lbc.GetPremultipliedColor(sx + lx, sy + ly, pm1)
If pm1.a <> pm2.a Or pm1.r <> pm2.r Or pm1.g <> pm2.g Or pm1.b <> pm2.b Then Return False
Next
Next
Return True
End Sub