B4A Library dgBarcode - an all-B4A barcodes library

EDIT: updated to version 0.12 (see below)

Hi all,

please find attached a barcode generation library entirely based on B4A code.
Current version is alpha so it is limited to a couple of symbologies (EAN/UPC).
I'm using it as a test-bed for a more general solution where the strict adherence to each symbology's tech specifications should be a must.
The lib interface is not final, so please read release notes when updating to a newer version.

A simple example about dgBarcode usage to display a barcode:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Dim bc As cls_barcode
   bc.Initialize

   Dim img1 As ImageView
   img1.Initialize("")
   Activity.AddView(img1,0dip,20dip,bc.CodeWidth(bc.Symbologies.EAN13),bc.CodeHeight(bc.Symbologies.EAN13))
   bc.DrawBarCode(bc.Symbologies.EAN13,"7617027005456",img1)
End Sub

A second example, useful to generate a barcode without displaying it :
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Dim bc As cls_barcode
   bc.Initialize

   Dim bm1 As Bitmap
   bm1.Initialize3(bc.GenerateBitmap(bc.Symbologies.EAN13,"7617027005456"))
end sub

And finally an example on how to use a few optional properties
B4X:
   'let's check the validity of a pair of codes
Log(bc.IsCodeValid(bc.Symbologies.UPCA,"614141012343")) 'valid
Log(bc.IsCodeValid(bc.Symbologies.UPCA,"614151012343")) 'wrong (check digit doesn't match)
'Let's compute the check digit for a given code
Log(bc.ComputeCheckDigit(bc.Symbologies.EAN13,"761702700545"))   'returns 6
'Let's modify colors to draw the code and its scale factor
bc.SetDrawingColors(Colors.Cyan,Colors.Yellow)                   'very poor contrast
bc.ScaleFactor = 2.0                                             'maximum scale factor

Feel free to suggest improvements and alternative design strategies. Enjoy.

Umberto

Version 0.12
- added method GenerateBitmap to return a bitmap ready to be saved in a file or DB

Version 0.11
- added support for UPC-A symbology
- added method IsCodeValid to check for code integrity
- added catch-all drawing for invalid codes (a light color rectangle with two crossing dark color lines)

Version 0.10
initial version; support for EAN symbology only
 

Attachments

  • dgBarcode_011.zip
    7.9 KB · Views: 520
  • dgBarcode_012.zip
    8.4 KB · Views: 697
Last edited:

DonManfred

Expert
Licensed User
Longtime User
  • Like
Reactions: udg

BjoernB

Member
Licensed User
this page says UPC-A codes are 12 characters long, but i still get the X instead of a barcode

B4X:
Dim bc As cls_barcode
bc.Initialize
    
ivBar.Width = bc.CodeWidth(bc.Symbologies.UPCA)
ivBar.Height = bc.CodeHeight(bc.Symbologies.UPCA)
bc.DrawBarCode(bc.Symbologies.UPCA,"123456654321",ivBar)

worked with 13 characters in EAN13, but the number i wanna display is just 12 long :(
 

udg

Expert
Licensed User
Longtime User
That was because 123456654321 seems to be not a valid UPCA code. Try with 614141012343
If you want to check for validity you can use
B4X:
Log(bc.IsCodeValid(bc.Symbologies.UPCA,"614141012343"))    'valid
Log(bc.IsCodeValid(bc.Symbologies.UPCA,"123456654321"))    'not valid
 

BjoernB

Member
Licensed User
That was because 123456654321 seems to be not a valid UPCA code. Try with 614141012343
If you want to check for validity you can use
B4X:
Log(bc.IsCodeValid(bc.Symbologies.UPCA,"614141012343"))    'valid
Log(bc.IsCodeValid(bc.Symbologies.UPCA,"123456654321"))    'not valid

i see, UPCA won't work for me, because i need 12 actual characters, not 11 + check digit
thanks :)

so i guess i have to use EAN13 and add the check digit myself ?
am i right?

EDIT: just found the "ComputeCheckDigit" Sub.
sorry, i'm not that used to Barcodes and didn't actually know i need a check Digit.
 
Last edited:
Top