B4A Library ZXingLib by icefairy333 - modified by Johan Schoeman (Scan QR Codes and other 1D/2D Barcodes)

Johan Schoeman

Expert
Licensed User
Longtime User
Will amend the library and then post a new set of library files.
 

JTmartins

Active Member
Licensed User
Longtime User
I remember this feature !!! it's actually very usefull when scanning barcodes in dark areas like wharehouses...As long as the device has a torch..obviously.
 

Johan Schoeman

Expert
Licensed User
Longtime User
Try with the new attached library files. I have tested it on a device with a flash/torch and on a device without a flash/torch - seems to be working.
 

Attachments

  • b4aZXING.zip
    11.9 KB · Views: 470
  • JhsIceZxing1NewLibFiles.zip
    438.7 KB · Views: 472

MarcoRome

Expert
Licensed User
Longtime User
Hi Johan. In a device i have this effect ( inverted image ). 4 works properly but about a device i see inverted image.



The code is :
B4X:
'    ImageView1.Background = Null
   
    zx.isportrait = True
    zx.useFrontCam = False
    zx.timeoutDuration = 30
   

    zx.theViewFinderXfactor = 0.7      'portrait x schermo pieno = 1
    zx.theViewFinderYfactor = 0.5      'portrait x schermo pieno = 1
   
 
   
    zx.theFrameColor = Colors.Black
    zx.theLaserColor = Colors.Red
    zx.theMaskColor = Colors.Black 'Colors.argb(255, 0, 0, 255)
    zx.theResultColor = Colors.ARGB(255, 238,187,117)
    zx.theResultPointColor = Colors.Yellow
    zx.mustBeep = True
    zx.mustVibrate = True
   

   
    zx.BeginScan("myzx")

Any idea ?
Thank you
Marco
 

Johan Schoeman

Expert
Licensed User
Longtime User
Best is to keep the orientation of the device as is and stand on your head when you scan the barcodes....

Jokes aside - what happens when you use this same device in landscape mode (remember to also do the change in the Manifest to landscape). Is it then still upside down?
 

MarcoRome

Expert
Licensed User
Longtime User

I tried to scan the QR Code, putting it on the client's head and I must say it works great .
Hi Johan and thank you for your response.
Yes in landscape havent this problem but in portrait yes. ( This only about Nexus 5 ).
 

Johan Schoeman

Expert
Licensed User
Longtime User
I tried to scan the QR Code, putting it on the client's head and I must say it works great .
Hi Johan and thank you for your response.
Yes in landscape haven't this problem but in portrait yes. ( This only about Nexus 5 ).
This is not a very tidy solution but you can use it to sort out the issue on the Nexus 5. I have added the ability to specify the display orientation.

B4X:
    zx.displayOrientation = 90     '90 is the default value that was set in the library. It works for most devices
                                   'although for eg the Nexus 5 will show an upside down preview with this setting.
                                   'I guess zx.displayOrientation = 270 will fix it for the Nexus 5 when used in portrait mode.


zx.displayOrientation = .... will only take effect if portrait mode is specified:
B4X:
    zx.isportrait = True

The default value in the library is 90 as it seems to work for most devices. If you don't specify zx.displayOrientation = .... in the code then 90 will automatically be applied. I guess for the Nexus 5 zx.displayOrientation = 270 will do the trick. Have not checked the forum if there is a way to determine the type of device that one is using. If there is then you can take care of other types of devices with a similar problem via B4A code.

Sample project and new lib files attached.

For what it might be worth, read the postings at this link
https://github.com/zxing/zxing/issues/484

There seems to be a solution incorporated in newer versions of ZXING (newer than what this library is based on) but it will take some serious open heart surgery to adapt the existing code - therefore the "quick fix"
 

Attachments

  • JhsIceZxing1LibFiles.zip
    438.8 KB · Views: 385
  • b4aZXING.zip
    12 KB · Views: 317

Johan Schoeman

Expert
Licensed User
Longtime User
This update is based on a request from @Carlos marin. Posting updated library files and a B4A project (for demonstration purposes) that will allow you to select between normal and color inverted codes to be scanned:
1. Normal = white background and black modules
2. Inverted = black background and white modules.

Use the spinner to make your selection for either normal or inverted codes to be scanned. Added this code to the spinner:
B4X:
Sub Spinner1_ItemClick (Position As Int, Value As Object)
   
    If Spinner1.SelectedIndex = 0 Then zx.scanInvertedCodes = False                     'scan normal colored codes (i.e background = white and modules = black)
    If Spinner1.SelectedIndex = 1 Then zx.scanInvertedCodes = True                      'scan inverted colored codes (i.e background = black and modules = white)
       
End Sub


Select from the spinner and click SCAN CODE:


NORMAL CODE (i.e white background and black modules)


INVERTED CODE (i.e black background and white modules)
 

Attachments

  • b4aZXING.zip
    12.2 KB · Views: 313
  • JhsIceZxing1NewLibFiles.zip
    439 KB · Views: 367

Johan Schoeman

Expert
Licensed User
Longtime User
This is an update of the library as amended previously in post #90. It will now automatically scan normal and inverted colored codes. No need to select from the spinner for choosing between normal and inverted codes. I have removed the spinner from the attached B4A example.

 

Attachments

  • JhsIceZxing1NewLibFiles.zip
    439 KB · Views: 396
  • b4aZXING.zip
    11.9 KB · Views: 355

MarcoRome

Expert
Licensed User
Longtime User
Hi great Johan. When i try ( last library #91 but also more "old" library ) with Samsung S7 Edge i have this result in Log Panel :


but even xxx_result dont work.
B4X:
Sub myzx_result(atype As String, Value As String, image As Bitmap)
       
   
    Log("type:" & atype &  "Value:" & Value)
   

End Sub

Any idea ??
 

Johan Schoeman

Expert
Licensed User
Longtime User
And you are trying it with the B4A project in #91?
 

Johan Schoeman

Expert
Licensed User
Longtime User
Try this one - I just need to add some code to return info to the B4A project. But it is far better.

https://www.b4x.com/android/forum/t...zxing-project-as-it-is-on-10-july-2016.68829/
 

Johan Schoeman

Expert
Licensed User
Longtime User

nw11

Member
Licensed User
Longtime User
if i scan a qrcode without torch (off) the library works correctly and fire xxx_result .. if i scan a qrcode with torch (on) the Library don't fire xxx_result and exit from the app immediatly after scan

can someone help me ?

tnk in advance

ps: the library used is #91
 

Johan Schoeman

Expert
Licensed User
Longtime User
I have tested it on two devices and on both the myzx_result gets fired regardless of the torch being on or off. I have nevertheless changed the wrapper for the event to be raised from a different thread. Attached is the amended library files. See if it sorts out your problem.
 

Attachments

  • JhsIceZxing1DiffThread.zip
    437.8 KB · Views: 340

kokixy

New Member
Licensed User
Longtime User
Hi!
This library worked flawlessly on my phone previously, but now (i think after Android 6.0.1 update) it exits from the app immediately after scan. It doesn't fire xxx_result. I don't see any relation with the torch. I have a Note4, but it's also doesn't work on a fresh updated S7. I'm using it in portrait mode, if it counts.
Please help.
Thanks!
 
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…