Android Question Barcode Reader - Improved

MrKim

Well-Known Member
Licensed User
Longtime User
Here is my solution to the questions asked here:
https://www.b4x.com/android/forum/t...-based-on-google-play-services-vision.118983/
https://www.b4x.com/android/forum/threads/crop-cameraex-preview.114596/
And question #5 here https://www.b4x.com/android/forum/t...on-google-play-services-vision.89705/#content


I too, needed to limit the focus since our shop paper contains many barcodes close together. This modification of Erel's barcode solution does as he suggested and creates a bitmap from the camera data and crops it. It also draws a box on the screen to show the user where to place the barcode.

Note, my original thought was place another window on the screen with the cropped area in it but I found it lagged too much. The code for that is still there but commented out. Edit: While driving today I realized my thought here lagged because I put it inside the sampling timer - duh. move it B4 the timer and it should work.

The relevant code is in Camera1_Preview.

As an aside, one of the things I did to help avoid reading the wrong code is wait until the same code is read twice before finalizing (that code is not apart of this example so here is what I did

B4X:
Private Sub FoundBarcode (msg As String)

    #IF DEBUG
        Toast.Show($"Found [Color=Blue][b][plain]${msg}[/plain][/b][/Color]"$, Null)
    #End If
    Log(msg)
    If ReadTxt = "" Then
        ReadTxt = msg
        Return
    Else If  ReadTxt2 = "" Then
        ReadTxt2 = msg
        If ReadTxt = ReadTxt2 Then  'we are done reading
            StopCamera
            Toast.Show(ReadTxt2, Null)
        Else  'try again
            ReadTxt = ""
            ReadTxt2 = ""
            Return
        End If
    End If
.
.
.

Also want to mention that with tablets - in this case a Lenovo 8 inch I have had a very hard time getting clean reads on 2d barcodes. That is why we added 3d codes to out Traveler's. I have found it reads MUCH better when the reading area is limited as I have done here.

Since all of this took me some time to figure out I thought sharing this might save someone some time.

Note: I have only done the Android version.
 

Attachments

  • BarCodeReader.zip
    184 KB · Views: 643
Last edited:

hung

Active Member
Licensed User
Longtime User
This is simple and quick. Thanks.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…