Sub Process_Globals
Private mbmp As Bitmap
Private faces() As Object
Private faceDetector As JavaObject
End Sub
Sub Globals
Private cvs As Canvas
End Sub
Sub Activity_Create(FirstTime As Boolean)
Dim bmp As Bitmap = LoadBitmap(File.DirAssets, "IMG_1516.JPG")
If FirstTime Then
PrepareFaceDetection(bmp.Width, bmp.Height, 3)
End If
cvs.Initialize2(mbmp)
Dim num As Int = FindFaces(bmp)
For i = 0 To num - 1
Dim f As JavaObject = faces(i)
GetMidPoint(f)
Next
End Sub
Sub GetMidPoint(Face As JavaObject)
Dim p As JavaObject
p.InitializeNewInstance("android.graphics.PointF", Null)
Face.RunMethod("getMidPoint", Array As Object(p))
Log("x: " & p.GetField("x"))
Log("y: " & p.GetField("y"))
End Sub
Sub PrepareFaceDetection(Width As Int, Height As Int, MaxNumberOfFaces As Int)
Dim jo As JavaObject
jo.InitializeStatic("android.graphics.Bitmap")
mbmp = jo.RunMethod("createBitmap", Array As Object(Width, Height, "RGB_565"))
Dim ar, face As JavaObject
ar.InitializeStatic("java.lang.reflect.Array")
face.InitializeStatic("android.media.FaceDetector$Face")
faces = ar.RunMethod("newInstance", Array As Object(face, MaxNumberOfFaces))
faceDetector.InitializeNewInstance("android.media.FaceDetector", Array As Object(Width, Height, MaxNumberOfFaces))
End Sub
Sub FindFaces(bmp As Bitmap) As Int
Dim destRect As Rect
destRect.Initialize(0, 0, mbmp.Width, mbmp.Height)
cvs.DrawBitmap(bmp, Null, destRect)
Return faceDetector.RunMethod("findFaces", Array As Object(mbmp, faces))
End Sub