B4J Tutorial Barcodes - QR Codes, PDF417, Aztec Codes, Code11, Code39, Code93, EAN8, EAN13, and Code128

Discussion in 'B4J Tutorials' started by Johan Schoeman, Aug 14, 2015.

  1. Johan Schoeman

    Johan Schoeman Expert Licensed User

    This is my first attempt at B4J. Have not tried to do anything special to the layout etc. The aim was to get back the correct binary strings to draw Code11, Code39, Code93, EAN8 and EAN13 barcodes with. All the code are in the main module as well as modules for each of the types of barcodes. The B4J project also includes a class called StringUtilities that the project makes use of. This class contains 38 string manipulation methods making use of inline java code.

    Each of the barcode modules return a binary string (1's and 0's). You need to draw an equal sized bar (width and height) for each 1 (black) and for each 0 (white). For eg, 11 will be two black bars next to one another, 10 will be a black bar followed by a white bar, 00 will be two consecutive white bars, and 01 will be a white bar followed by a black bar.

    The barcodes generated for EAN8 and EAN13 includes the parity bits - take note that the label next to them only shows the original input message for EAN8 and EAN13 barcodes. You can amend the code in the B4J project to your own liking and for eg return an array of strings that contains for eg (1) the binary string of the input message and (2) the parity bit/number for EAN8 or EAN13 barcodes. Very simple to do and I leave it up to whoever wants to use this project.

    Have not fully amended the error checking for valid input messages. Simple to do and I leave it up to whoever wants to use this B4J project.

    This project is based on my B4A project that you can find here. Just busy amending it so that it can be used in B4J. Have tested/scanned each of Code11, Code39, Code93, EAN8 and EAN13 with QRCPV4 that you can find here.

    I will add Code128, Aztec Codes, PDF417, and QR Codes (as what I have inside the B4A project) as and when time permits.

    No internet connection is required to generate the barcodes - all the code are in the code modules.

    Edit: see project in post #9. It generates QRCodes, PDF417, Aztec Codes, Code11, Code39, Code93, EAN8, EAN13, and Code128

    1.png
     

    Attached Files:

    Last edited: Aug 22, 2015
  2. Johan Schoeman

    Johan Schoeman Expert Licensed User

    Replace the code in Sub Button1_MouseClicked (EventData AsMouseEvent) with the code below

    Code:
    Sub Button1_MouseClicked (EventData As MouseEvent)

        Label1.Visible = 
    True
        Label2.Visible = 
    True
        Label3.Visible = 
    True 
        Label4.Visible = 
    True
        Label5.Visible = 
    True

        
    Dim binstring As String = ""
        
    Dim msg, prefix, postfix As String
        msg = 
    "12345"
        prefix = 
    "A"
        postfix = 
    "B"
        binstring = Code11.Draw_Code11(msg, prefix, postfix)
        
    Log("binstring Code11 = " & binstring)
        draw_barcode_Code11(binstring)
        Label1.Text = prefix & msg & postfix & 
    Chr(10) & Chr(13) & "Code 11 Barcode"
     
        msg = 
    "987654"
        binstring = Code39.Draw_Code39(msg)
        
    Log("binstring Code39 = " & binstring)
        draw_barcode_Code39(binstring) 
        Label2.Text = msg & 
    Chr(10) & Chr(13) & "Code 39 Barcode"
     
        msg = 
    "234567"
        binstring = Code93.Draw_Code93(msg)
        
    Log("binstring Code93 = " & binstring) 
        draw_barcode_Code93(binstring)
        Label3.Text = msg & 
    Chr(10) & Chr(13) & "Code 93 Barcode"
     
        msg = 
    "1234567"
        binstring = EAN8.Draw_EAN8(msg)
        
    Log("binstring EAN8 = " & binstring)     
        draw_barcode_EAN8(binstring)     
        Label4.Text = msg & 
    Chr(10) & Chr(13) & "EAN 8 Barcode"
     
        msg = 
    "123456789012"
        binstring = EAN13.Draw_EAN13(msg)
        
    Log("binstring EAN13 = " & binstring)     
        draw_barcode_EAN13(binstring) 
        Label5.Text = msg  & 
    Chr(10) & Chr(13) & "EAN 13 Barcode" 
     
    End Sub
    ...and then you should get this (indicating the type of barcode inside the label as well):

    2.png
     
    Last edited: Aug 15, 2015
    jcohedman, jsanchezc and rboeck like this.
  3. Johan Schoeman

    Johan Schoeman Expert Licensed User

    Attached project adds Code 128 barcodes.

    3.png
     

    Attached Files:

    jsanchezc and rboeck like this.
  4. Johan Schoeman

    Johan Schoeman Expert Licensed User

    Attached project adds PDF417 2D barcodes (no internet connection required)
    Thanks Erel ;)

    5.png
     

    Attached Files:

    jsanchezc, jmon, micro and 1 other person like this.
  5. Johan Schoeman

    Johan Schoeman Expert Licensed User

    The attached project adds Aztec Codes (layer 1 to layer 11) to the barcodes already posted in the previous projects. Use something like NeoReader to scan the PDF417 and Aztec codes with.

    6.png
     

    Attached Files:

  6. rboeck

    rboeck Well-Known Member Licensed User

    Do we have the possibility to read Aztec and PDF417 Barcode on android?

    Just found: neoreader does it all!
     
    Johan Schoeman likes this.
  7. Johan Schoeman

    Johan Schoeman Expert Licensed User

  8. Johan Schoeman

    Johan Schoeman Expert Licensed User

    The attached project adds QR Codes (Version 1 to Version 40) to the barcodes already posted in the previous projects. Use something like NeoReader or this to scan the QR Codes with.

    I will try and spend a bit of additional time on it to redo the drawing of the 1D barcodes by adding their code back into the various code modules. Will also add the possibility to change the fore color and back color of the barcodes as well as the size of the bars in the 1D barcodes and the modules in the 2D codes.

    (Can I say that I am reasonably proud of my very first B4J project...:cool:. There are 10 380 lines of code in the code modules to generate these barcodes with)

    7.png
     

    Attached Files:

    Last edited: Aug 21, 2015
  9. Johan Schoeman

    Johan Schoeman Expert Licensed User

    Attached project refers:
    1. Have moved the drawing methods of the 1D barcodes into the applicable code modules
    2. Have added functionality to accommodate a foreground and background color
    3. Have added functionality to accommodate 1D bar widths and 2D module sizes.

    The End.

    8.png
     

    Attached Files:

  10. rboeck

    rboeck Well-Known Member Licensed User

    Hi johan,

    currently i want to try your last examples, but i can't compile it in debug mode; in release mode it works without problems. Maybe my java options are not usefull?
    Thanks!
    Reinhard
     

    Attached Files:

  11. Erel

    Erel Administrator Staff Member Licensed User

    You will need to reduce the size of the mentioned sub.
     
  12. Johan Schoeman

    Johan Schoeman Expert Licensed User

    The code modules that have the code for PDF417, Aztec Codes, and QR Codes are lengthy and will not compile in debug mode (as per Erel's post above). You will need to break these 3 code modules into a number of smaller code modules to compile it in debug mode. Shout if you need some assistance - will gladly assist.
     
    Last edited: Aug 31, 2015
  13. rboeck

    rboeck Well-Known Member Licensed User

    Hi johan,

    i have tried to reduce the size of some subs and now i have a running debug version of qrcode.bas. I have splitted the longest sub in four parts. Maybe you could take a look on it and check it under some circumstances before some one else use a maybe problematic version.
     

    Attached Files:

    Johan Schoeman likes this.
  14. Johan Schoeman

    Johan Schoeman Expert Licensed User

    Hi @rboeck

    Have not downloaded it yet. Is it working for you after you have done the split? Can you now compile it in debug mode? From your post above it seems to me as if you have it working. I have written the QR code project in such a way that it will automatically decide what version QR code should be used based on the input message. So, if you want to test it then give it a fairly long input message and pass the required error level and mask pattern to apply. If it then scans - well, Bob's your uncle...will nevertheless download and test sometime tonight. But well done on the split!
     
    Last edited: Sep 1, 2015
  15. Johan Schoeman

    Johan Schoeman Expert Licensed User

    Your mod to the code seems to be working 100%. Have just added a long string of data that returned a Version 10 QR Code and it scans perfectly. Noticed your changes to the various select_block subs that the original sub was broken into. ;)
     
  16. rboeck

    rboeck Well-Known Member Licensed User

    I tried first to reduce the size with optimization; but after many tries the problem in debug mode persists; so it changed my strategy and splitted the biggest sub and this worked. I could try to use two dimensional array for ver, but it is much work and the code is already working.
    Thanks for your work,
    Reinhard
     
    Johan Schoeman likes this.
  17. rboeck

    rboeck Well-Known Member Licensed User

    I could not resist to further optimize and shorten your code: now i could reduce it to 35% of the original size; as long as i see, the functionality is still alive. The biggest thing was to get the values in an 2 dimensional array; then many things could be extremly shortened. All select_clock lines are now 42 lines.
    When i begin, i also had no idea how to make it; but this project leads me to learn how to use two dimensional arrays.
    Reinhard
     

    Attached Files:

    ellpopeb4a and Johan Schoeman like this.
  18. JTmartins

    JTmartins Active Member Licensed User

    Rboeck, I just tried your code as in previous post, and I still get a "Error to large for try statement..." in debug mode.

    Can you compile it in debug mode ? (B4J 4.01 and jdk1.8.0_45 here)

    Thanks

    JM
     
  19. rboeck

    rboeck Well-Known Member Licensed User

    Hi JTmartins,

    i was unprecise in my previous posts - my interest was primary in qr code generation and my work only changed this module. In my working project i have remarked pdf417 and actec code (line 124 to line 141) and removed the modules. In this form it compiles in debug mode. I use B4J 4.2 beta and jdk1.8.0_65
     
  20. skeedsr

    skeedsr Member

    hi johan thank for the exhample, i have some issue, in de code 128 i cant write long word like "01aaviocomm12".

    I look that axept only 8 caracter, but usually the 128 code axept more.

    thanks!

    Livio
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice