Android Question Barcode Reader Class By Erel Based on Google Play Services Vision

Mahares

Expert
Licensed User
Longtime User
I am just starting to get a feel for the barcode reader class created by Erel here: https://www.b4x.com/android/forum/t...on-google-play-services-vision.89705/#content
  1. When you scan a barcode, you get a continuous log of the barcode scanned. I would like that as soon as one barcode is scanned the scanning to stop and use the scanned value to look up data in a database or a file.
  2. Once a barcode is scanned, how can you show the type of barcode scanned from the list: CODE_39, QR_CODE, etc. Thank you
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
In Camera1_Preview:
B4X:
Sub Camera1_Preview (data() As Byte)
   If SearchForBarcodes Then '<----------------------
       If DateTime.Now > LastPreview + IntervalBetweenPreviewsMs Then
           'Dim n As Long = DateTime.Now
           cvs.ClearRect(cvs.TargetRect)
           Dim frameBuilder As JavaObject
           Dim bb As JavaObject
           bb = bb.InitializeStatic("java.nio.ByteBuffer").RunMethod("wrap", Array(data))
           frameBuilder.InitializeNewInstance("com/google/android/gms/vision/Frame.Builder".Replace("/", "."), Null)
           Dim cs As CameraSize = camEx.GetPreviewSize
           frameBuilder.RunMethod("setImageData", Array(bb, cs.Width, cs.Height,  842094169))
           Dim frame As JavaObject = frameBuilder.RunMethod("build", Null)
           Dim SparseArray As JavaObject = detector.RunMethod("detect", Array(frame))
           LastPreview = DateTime.Now
           For i = 0 To SparseArray.RunMethod("size", Null) - 1
               Dim barcode As JavaObject = SparseArray.RunMethod("valueAt", Array(i))
               Dim raw As String = barcode.GetField("rawValue")
               Log(raw)
               Dim format As Int = barcode.GetField("format") '<----------------------
               
               ToastMessageShow("Found: " & raw, True)
               Dim points() As Object = barcode.GetField("cornerPoints")
               Dim tl As JavaObject = points(0)
'               Dim tr As JavaObject = points(1)
               Dim br As JavaObject = points(2)
'               Dim bl As JavaObject = points(3)
               Dim r As B4XRect
               r.Initialize(tl.GetField("x"), tl.GetField("y"), br.GetField("x"), br.GetField("y"))
               cvs.DrawRect(r, Colors.Red, False, 5dip)
               cvs.Invalidate
           Next
           
           'Log(DateTime.Now - n)
       End If
   End If
End Sub
 
Upvote 0
Top