iOS Question generate barcode b4i

Uniko Sistemi srl

Active Member
Licensed User
Hello everybody.
I use the b4x project and I would need some help. does anyone know how to generate a code39 barcode on ios because for android i already did it. can someone help me ?
thank you all
 

Johan Hormaza

Well-Known Member
Licensed User
Longtime User
B4X:
Public Sub PaintBarCode( xCanvas As Canvas, xLeft As Int,  xTop As Int, xHeight As Int, xCode As String, xThicknes As Float)
Dim intercharacterGap As String = "0"
Dim str As String
Dim alphabet39 As String = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%*"
Dim coded39Char() As String = Array As String("000110100", "100100001", "001100001", "101100000", "000110001", "100110000", _
  "001110000", "000100101", "100100100", "001100100", "100001001", "001001001", _
  "101001000", "000011001", "100011000", "001011000", "000001101", "100001100", _
  "001001100", "000011100", "100000011", "001000011", "101000010", "000010011", _
  "100010010", "001010010", "000000111", "100000110", "001000110", "000010110", _
  "110000001", "011000001", "111000000", "010010001", "110010000", "011010000", _
  "010000101", "110000100", "011000100", "010101000", "010100010", "010001010", _
  "000101010", "010010100")

  If xCode = "" Then
        Return
    End If
  str = "*" & xCode.ToUpperCase & "*"

  For i = 0 To xCode.Length - 1
        If alphabet39.IndexOf( xCode.CharAt(i)) = -1 Or xCode.CharAt(i) = "*" Then
        Return
    End If
  Next

  Dim encodedString As String = ""

    For i  = 0 To str.Length - 1
    If i > 0 Then
            encodedString = encodedString & intercharacterGap
    End If
   encodedString = encodedString & coded39Char(alphabet39.IndexOf(str.CharAt(i)))
  Next

  Dim encodedStringLength As Int = encodedString.Length
    Dim wideToNarrowRatio As Float = 3

    Dim x As Float = 0
    Dim wid As Float = 0

  x = xLeft
  For i = 0 To encodedStringLength - 1
    If encodedString.CharAt(i) = "1" Then
            wid = wideToNarrowRatio * xThicknes
    Else
            wid = xThicknes
    End If

        Dim d2 As Rect
        d2.Initialize(  x, xTop,  x+ wid,  xHeight)
        xCanvas.DrawRect(d2, IIf(i Mod 2 = 0, Colors.Black, Colors.WHITE), True, wid)
    x = x + wid
  Next


 End Sub
 
Upvote 0

Uniko Sistemi srl

Active Member
Licensed User
B4X:
Public Sub PaintBarCode( xCanvas As Canvas, xLeft As Int,  xTop As Int, xHeight As Int, xCode As String, xThicknes As Float)
Dim intercharacterGap As String = "0"
Dim str As String
Dim alphabet39 As String = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%*"
Dim coded39Char() As String = Array As String("000110100", "100100001", "001100001", "101100000", "000110001", "100110000", _
  "001110000", "000100101", "100100100", "001100100", "100001001", "001001001", _
  "101001000", "000011001", "100011000", "001011000", "000001101", "100001100", _
  "001001100", "000011100", "100000011", "001000011", "101000010", "000010011", _
  "100010010", "001010010", "000000111", "100000110", "001000110", "000010110", _
  "110000001", "011000001", "111000000", "010010001", "110010000", "011010000", _
  "010000101", "110000100", "011000100", "010101000", "010100010", "010001010", _
  "000101010", "010010100")

  If xCode = "" Then
        Return
    End If
  str = "*" & xCode.ToUpperCase & "*"

  For i = 0 To xCode.Length - 1
        If alphabet39.IndexOf( xCode.CharAt(i)) = -1 Or xCode.CharAt(i) = "*" Then
        Return
    End If
  Next

  Dim encodedString As String = ""

    For i  = 0 To str.Length - 1
    If i > 0 Then
            encodedString = encodedString & intercharacterGap
    End If
   encodedString = encodedString & coded39Char(alphabet39.IndexOf(str.CharAt(i)))
  Next

  Dim encodedStringLength As Int = encodedString.Length
    Dim wideToNarrowRatio As Float = 3

    Dim x As Float = 0
    Dim wid As Float = 0

  x = xLeft
  For i = 0 To encodedStringLength - 1
    If encodedString.CharAt(i) = "1" Then
            wid = wideToNarrowRatio * xThicknes
    Else
            wid = xThicknes
    End If

        Dim d2 As Rect
        d2.Initialize(  x, xTop,  x+ wid,  xHeight)
        xCanvas.DrawRect(d2, IIf(i Mod 2 = 0, Colors.Black, Colors.WHITE), True, wid)
    x = x + wid
  Next


 End Sub


thanks, what do I call this routine?
 
Upvote 0
Top