Sample code for 30+ languages & platforms
Visual Basic 6.0 Requires Chilkat v11.7.0+

Get the Modules of a QR Code (Bit Matrix)

See more QR Code Examples

Demonstrates getting the QR code itself, as a grid of dark and light modules, to draw with something other than the built-in PNG and SVG output: on a canvas, in a PDF, on a display, or with a label printer language. With output.includeModuleData the response has symbols[0].moduleData, a bit matrix with one bit per module, each row starting on a new byte, most significant bit first, 1 for dark. The quiet zone is not part of the matrix. The example prints the symbol using two characters per module.

Chilkat Visual Basic 6.0 Downloads

Visual Basic 6.0
Dim success As Long
success = 0

'  This example requires the Chilkat API to have been previously unlocked.
'  See Global Unlock Sample for sample code.

Dim json As New ChilkatJsonObject
success = json.UpdateString("payload.text","CHILKAT")
success = json.UpdateBool("output.includeModuleData",1)

Dim fmt As New ChilkatFormats
Dim jsonOut As New ChilkatJsonObject
success = fmt.QrCode("generate",json,jsonOut)
If (success = 0) Then
    Debug.Print fmt.LastErrorText
    Exit Sub
End If

Dim width As Long
width = jsonOut.IntOf("symbols[0].moduleData.width")
Dim height As Long
height = jsonOut.IntOf("symbols[0].moduleData.height")
Dim rowBytes As Long
rowBytes = jsonOut.IntOf("symbols[0].moduleData.rowBytes")
Debug.Print "kind: " & jsonOut.StringOf("symbols[0].moduleData.kind")
Debug.Print "modules: " & width & " x " & height & ", " & rowBytes & " bytes per row"

'  The matrix is height rows of rowBytes bytes.
Dim bd As New ChilkatBinData
success = bd.AppendEncoded(jsonOut.StringOf("symbols[0].moduleData.bytesBase64"),"base64")
If (success = 0) Then
    Debug.Print bd.LastErrorText
    Exit Sub
End If

Dim sbRow As New ChilkatStringBuilder
Dim row As Long
Dim col As Long
Dim b As Long
Dim mask As Long
mask = 128
For row = 0 To height - 1
    sbRow.Clear 
    For col = 0 To width - 1
        '  The module at (col,row) is a bit of the byte at (row * rowBytes) + (col / 8).
        '  The leftmost module of each byte is its most significant bit.
        If ((col Mod 8) = 0) Then
            mask = 128
        End If

        b = bd.GetByte((row * rowBytes) + (col / 8))
        If (((b / mask) Mod 2) = 1) Then
            success = sbRow.Append("##")
        Else
            success = sbRow.Append("  ")
        End If

        mask = mask / 2
    Next
    Debug.Print sbRow.GetAsString()
Next

'  The same symbol as the PNG that the call also returned:

'  image

'  Sample output:

'  kind: bitMatrix
'  modules: 21 x 21, 3 bytes per row
'  ##############              ##############
'  ##          ##      ####    ##          ##
'  ##  ######  ##  ##  ####    ##  ######  ##
'  ##  ######  ##  ##          ##  ######  ##
'  ##  ######  ##  ##  ##  ##  ##  ######  ##
'  ##          ##  ####  ##    ##          ##
'  ##############  ##  ##  ##  ##############
'                  ####
'  ##  ##########      ####    ##########
'      ####          ##  ########    ######
'  ####  ########    ####  ##  ####      ####
'        ##  ##      ############    ####  ##
'    ######  ####  ######  ##    ##  ##
'                  ##  ##  ##    ##  ##    ##
'  ##############        ##  ##    ##      ##
'  ##          ##  ##  ##        ######  ####
'  ##  ######  ##  ####  ##  ##    ##
'  ##  ######  ##  ##  ############    ##
'  ##  ######  ##  ##      ##  ####  ##
'  ##          ##    ##  ########          ##
'  ##############  ##      ##      ######