AutoIt Requires Chilkat v11.7.0+
AutoIt
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 AutoIt Downloads
Local $bSuccess = False
; This example requires the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
$oJson = ObjCreate("Chilkat.JsonObject")
$oJson.UpdateString("payload.text","CHILKAT")
$oJson.UpdateBool("output.includeModuleData",True)
$oFmt = ObjCreate("Chilkat.Formats")
$oJsonOut = ObjCreate("Chilkat.JsonObject")
$bSuccess = $oFmt.QrCode("generate",$oJson,$oJsonOut)
If ($bSuccess = False) Then
ConsoleWrite($oFmt.LastErrorText & @CRLF)
Exit
EndIf
Local $iWidth = $oJsonOut.IntOf("symbols[0].moduleData.width")
Local $iHeight = $oJsonOut.IntOf("symbols[0].moduleData.height")
Local $iRowBytes = $oJsonOut.IntOf("symbols[0].moduleData.rowBytes")
ConsoleWrite("kind: " & $oJsonOut.StringOf("symbols[0].moduleData.kind") & @CRLF)
ConsoleWrite("modules: " & $iWidth & " x " & $iHeight & ", " & $iRowBytes & " bytes per row" & @CRLF)
; The matrix is height rows of rowBytes bytes.
$oBd = ObjCreate("Chilkat.BinData")
$bSuccess = $oBd.AppendEncoded($oJsonOut.StringOf("symbols[0].moduleData.bytesBase64"),"base64")
If ($bSuccess = False) Then
ConsoleWrite($oBd.LastErrorText & @CRLF)
Exit
EndIf
$oSbRow = ObjCreate("Chilkat.StringBuilder")
Local $iRow
Local $iCol
Local $iB
Local $iMask = 128
For $iRow = 0 To $iHeight - 1
$oSbRow.Clear
For $iCol = 0 To $iWidth - 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 (($iCol Mod 8) = 0) Then
$iMask = 128
EndIf
$iB = $oBd.GetByte(($iRow * $iRowBytes) + ($iCol / 8))
If ((($iB / $iMask) Mod 2) = 1) Then
$oSbRow.Append("##")
Else
$oSbRow.Append(" ")
EndIf
$iMask = $iMask / 2
Next
ConsoleWrite($oSbRow.GetAsString() & @CRLF)
Next
; The same symbol as the PNG that the call also returned:
;
; Sample output:
; kind: bitMatrix
; modules: 21 x 21, 3 bytes per row
; ############## ##############
; ## ## #### ## ##
; ## ###### ## ## #### ## ###### ##
; ## ###### ## ## ## ###### ##
; ## ###### ## ## ## ## ## ###### ##
; ## ## #### ## ## ##
; ############## ## ## ## ##############
; ####
; ## ########## #### ##########
; #### ## ######## ######
; #### ######## #### ## #### ####
; ## ## ############ #### ##
; ###### #### ###### ## ## ##
; ## ## ## ## ## ##
; ############## ## ## ## ##
; ## ## ## ## ###### ####
; ## ###### ## #### ## ## ##
; ## ###### ## ## ############ ##
; ## ###### ## ## ## #### ##
; ## ## ## ######## ##
; ############## ## ## ######